Instapy: Message: stale element reference: element is not attached to the page document

Created on 20 Oct 2018  路  6Comments  路  Source: timgrossmann/InstaPy

@sionking @uluQulu what does this error means?

Traceback (most recent call last):
File "InstaPy/5bba4f87475a3400131492df.py", line 26, in
session.interact_user_followers(['xx','xx'], amount=70, randomize=True)
File "/home/fredrik/InstaPy/instapy/instapy.py", line 2206, in interact_user_followers
self.logfolder)
File "/home/fredrik/InstaPy/instapy/unfollow_util.py", line 906, in get_given_user_followers
channel, jumps, logger, logfolder)
File "/home/fredrik/InstaPy/instapy/unfollow_util.py", line 713, in get_users_through_dialog
person_list = dialog_username_extractor(buttons)
File "/home/fredrik/InstaPy/instapy/unfollow_util.py", line 736, in dialog_username_extractor
if person and hasattr(person, 'text') and person.text:
File "/home/fredrik/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "/home/fredrik/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/home/fredrik/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/home/fredrik/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: headless chrome=70.0.3538.67)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-36-generic x86_64)

wontfix

Most helpful comment

same here
@uluQulu
@sionking
@timgrossmann

All 6 comments

Getting the same error.

same here
@uluQulu
@sionking
@timgrossmann

same here. Did anyone find a fix?

same error...

Traceback (most recent call last):
File "quickstart.py", line 42, in
session.follow_user_followers(['xx','tt','yy','zz'], amount=20, randomize=False, interact=True)
File "/root/InstaPy/instapy/instapy.py", line 2490, in follow_user_followers
self.logfolder)
File "/root/InstaPy/instapy/unfollow_util.py", line 881, in get_given_user_followers
channel, jumps, logger, logfolder)
File "/root/InstaPy/instapy/unfollow_util.py", line 720, in get_users_through_dialog
person_list = dialog_username_extractor(buttons)
File "/root/InstaPy/instapy/unfollow_util.py", line 743, in dialog_username_extractor
if person and hasattr(person, 'text') and person.text:
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webelement.py", line 76, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: headless chrome=70.0.3538.77)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.4.0-127-generic x86_64)

@Andercorp @fgisslen
Sorry, I could only look at it now cos I am not actively using InstaPy last times and have not much free time.
I have shared the fix at my live PR #3226 in e69243695a069d870bef4faf42864f9ed6d4313f commit.

The problem was happening when the given amount was less than ~20 (and the randomize was False cos with _randomization_ it triples the amount..).
In other words, once it did not enter the
while (total_list < amount) and not abort statement, it did produce that error.

Why?

buttons = get_buttons_from_dialog(dialog, channel)   # fresh references of the buttons
scroll_to_bottom_of_followers_list(browser, dialog)   # the change from #3159 which stales the elements referenced above
while (total_list < amount) and not abort:
    # scroll more
    # get the buttons again = fresh references of the buttons

As you can see, once it enters the while statement, it has the fresh references of the buttons, but if it does not, as there is no need to enter that statement cos the amount is less, then it will end up with the stale element references and throw that exception.


Cheers 馃榿

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thisishotdog picture thisishotdog  路  3Comments

CodeMaster1 picture CodeMaster1  路  3Comments

rahulkapoor90 picture rahulkapoor90  路  3Comments

v77v picture v77v  路  3Comments

neomh picture neomh  路  3Comments