InstaPy icon indicating copy to clipboard operation
InstaPy copied to clipboard

Selenium Unable to locate element

Open jtrieuDev opened this issue 7 years ago • 29 comments

Hi everyone, I hope you guys are doing well : ( I got the last version of commits )

the code I am using:

session.login()
session.set_relationship_bounds(enabled=False,
				 potency_ratio=-1.21,
				  delimit_by_numbers=False,
				   max_followers=4590,
				    max_following=5555,
				     min_followers=45,
				      min_following=77)
session.set_simulation(enabled=False)
session.set_skip_users(skip_private=True,
                       private_percentage=100,
                       skip_no_profile_pic=False,
                       no_profile_pic_percentage=100,
                       skip_business=False,
                       business_percentage=100,
                       skip_business_categories=[],
                       dont_skip_business_categories=[])
session.set_user_interact(amount=2, randomize=True, percentage=100, media='Photo')
session.set_do_like(enabled=True, percentage=100)
session.interact_user_followers(['user'], amount=1600, randomize=False)

the error I got

Traceback (most recent call last):
  File "like.py", line 57, in <module>
    session.interact_user_followers(['username'], amount=1600, randomize=False)
  File "/Users/user/Desktop/instagram/InstaPy/instapy/instapy.py", line 2801, in interact_user_followers
    self.logfolder)
  File "/Users/user/Desktop/instagram/InstaPy/instapy/unfollow_util.py", line 1082, in get_given_user_followers
    logger, logfolder)
  File "/Users/user/Desktop/instagram/InstaPy/instapy/unfollow_util.py", line 810, in get_users_through_dialog
    dialog = browser.find_element_by_xpath(dialog_address)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//body/div[2]/div/div[2]"}

Thank you for helping !

jtrieuDev avatar Apr 01 '19 23:04 jtrieuDev

same. might be the HTML changed

tzeiske avatar Apr 01 '19 23:04 tzeiske

I have the same error, I went back to following by tags. I'm presuming the element has changed location on the website.

masto182 avatar Apr 02 '19 00:04 masto182

Got the same error interacting whit the followers of my competitors, theres any solution?

CamiloB avatar Apr 02 '19 00:04 CamiloB

Same issue here.

Guitrentz avatar Apr 02 '19 00:04 Guitrentz

The dialog_address xpath in the unfollow_util.py needs to be changed. The followers dialog box opens successfully but it gets closed when it tries to scroll

jeremycjang avatar Apr 02 '19 00:04 jeremycjang

Don't have time to look into it right now, but hope that's a starting point someone can build off of!

jeremycjang avatar Apr 02 '19 00:04 jeremycjang

File: unfollow_util.py

Solution:

# find dialog box
dialog_address = "//body/div[3]/div/div[2]"
dialog = browser.find_element_by_xpath(dialog_address)

Before:

# find dialog box
dialog_address = "//body/div[2]/div/div[2]"
dialog = browser.find_element_by_xpath(dialog_address)

globsecure avatar Apr 02 '19 01:04 globsecure

Thanks @globsecure!!

panchoma avatar Apr 02 '19 01:04 panchoma

@globsecure thanks a lot works perfect for me !

CamiloB avatar Apr 02 '19 05:04 CamiloB

@globsecure works here, thanks!

thinhago avatar Apr 02 '19 06:04 thinhago

File: unfollow_util.py Solution:

find dialog box

dialog_address = "//body/div[3]/div/div[2]" dialog = browser.find_element_by_xpath(dialog_address)

Before:

find dialog box

dialog_address = "//body/div[2]/div/div[2]" dialog = browser.find_element_by_xpath(dialog_address)

Thanks @globsecure, worked perfectly!

Guitrentz avatar Apr 02 '19 11:04 Guitrentz

the solution is working, thank you @globsecure, I am closing this thread

jtrieuDev avatar Apr 02 '19 13:04 jtrieuDev

Thanks @globsecure for the solution, appreciate it! Quick question however: If I install instapy on a server via pip and then import the library in a Python script, it will still produce this error, right?

attilathury avatar Apr 02 '19 15:04 attilathury

I changed it, but now I got this error :

Cookie file not found, creating cookie... web_1 | Traceback (most recent call last): web_1 | File "code/docker_quickstart.py", line 14, in web_1 | session.login() web_1 | File "/code/instapy/instapy.py", line 360, in login web_1 | self.bypass_with_mobile): web_1 | File "/code/instapy/login_util.py", line 262, in login_user web_1 | "//button[text()='Log in']") web_1 | File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath web_1 | return self.find_element(by=By.XPATH, value=xpath) web_1 | File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element web_1 | 'value': value})['value'] web_1 | File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute web_1 | self.error_handler.check_response(response) web_1 | File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response web_1 | raise exception_class(message, screen, stacktrace) web_1 | selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()='Log in']"} web_1 | (Session info: chrome=72.0.3626.81) web_1 | (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.9.13-moby x86_64) web_1 | instapymaster2_web_1 exited with code 1

I guess an error is still on the file "Log in"

charlyonboard avatar Apr 02 '19 22:04 charlyonboard

Thanks @globsecure for the solution, appreciate it! Quick question however: If I install instapy on a server via pip and then import the library in a Python script, it will still produce this error, right?

Yeah...

Using: pip install -e . (Compile local)

BUT:

pip install instapy -U (solution on production)

globsecure avatar Apr 03 '19 02:04 globsecure

@globsecure amazing.. thank you.

j21w91 avatar Apr 03 '19 08:04 j21w91

@globsecure Awesome! Thank you! May one day I understand this stuff as you guys do. :)

dpascoa avatar Apr 03 '19 09:04 dpascoa

Now the issue is change to //body/div[3]/div/div[2] also failed.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate eleme t: {"method":"xpath","selector":"//body/div[3]/div/div[2]"} (Session info: chrome=73.0.3683.86) (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Window NT 6.1.7601 SP1 x86_64)

spikeyhair avatar Apr 03 '19 16:04 spikeyhair

I'm new to all this, how do I use the solution given?

jointyje avatar Apr 08 '19 14:04 jointyje

@jointyje which OS did you use ?

CamiloB avatar Apr 08 '19 14:04 CamiloB