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

For any of you having this issue on Mac.

I got it fixed by updating the app with update.command

alexguz79 avatar Apr 08 '19 16:04 alexguz79

@CamiloB i am using windows 8

jointyje avatar Apr 11 '19 08:04 jointyje

@CamiloB i am using windows 8

I believe the file to update on Windows is installations/Windows/update.bat

Give it a try.

alexguz79 avatar Apr 11 '19 13:04 alexguz79

I'm still getting this error "method":"xpath","selector":"//body/div[3]/div/div[2]"

I already used the update command on macOS

lucienemlf-zz avatar Apr 25 '19 19:04 lucienemlf-zz

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//body/div[3]/div/div[2]"}

GeoffreyPG avatar May 03 '19 19:05 GeoffreyPG

Message: no such element: Unable to locate element:

The error is right there. You might have the wrong xpath from the page you are working on. Try getting it again.

alexguz79 avatar May 03 '19 19:05 alexguz79

i try to change :

https://github.com/timgrossmann/InstaPy/blob/master/instapy/unfollow_util.py#L809

Old dialog_address = "//body/div[3]/div/div[2]"

New dialog_address = "//body/div[@ROLEhttps://github.com/ROLE="presentation"]/div/div[2]"

But same error


De : alexguz79 [email protected] Envoyé : vendredi 3 mai 2019 21:15 À : timgrossmann/InstaPy Cc : GeoffreyPG; Comment Objet : Re: [timgrossmann/InstaPy] Selenium Unable to locate element (#4240)

Message: no such element: Unable to locate element:

The error is right there. You might have the wrong xpath from the page you are working on. Try getting it again.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/timgrossmann/InstaPy/issues/4240#issuecomment-489209226, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALUNO3IM66PU5NMYCDZSQV3PTSFNNANCNFSM4HC3I2NA.

GeoffreyPG avatar May 03 '19 19:05 GeoffreyPG

I got the same error as the original post "Unable to locate element: {"method":"xpath","selector":"//body/div[2]/div/div[2]".

Changed it to the solution proposed by @globsecure, but now I'm just getting "Unable to locate element: {"method":"xpath","selector":"//body/div[2]/div/div[2]" instead.

I'm guessing Instagram has changed the UI again?

Running the latest build (0.4.2) with chromedriver 2.36.post0

martinkrulltott avatar May 11 '19 11:05 martinkrulltott

Don’t ignore this perspective https://azure-resource-managerwa.github.io/yVE4lFQ6v0nHfTchZo9q/

xsssilky avatar Oct 20 '25 17:10 xsssilky