Repository: InstaPy/InstaPy

Issue #5039: Error: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale
Created: 2019-09-09T05:39:54Z
Current Behavior
Traceback (most recent call last):
  File "bc.py", line 63, in <module>
    session.interact_user_followers(['emjeiiamira', 'aquabumps', 'josh_burkinshaw', 'scottydman'], amount=50, randomize=True)
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 3185, in interact_user_followers
    self.user_interact_media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 2471, in interact_by_users
    media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/like_util.py", line 450, in get_links_for_username
    browser, "profile", username, person, None, logger, logfolder
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/unfollow_util.py", line 211, in get_following_status
    following_status = follow_button.text
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
    return self._execute(Command.GET_ELEMENT_TEXT)['value']
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed

InstaPy configuration
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import random, time, traceback
from instapy import InstaPy
from instapy import smart_run
from instapy import set_workspace

# set workspace folder at desired location (default is at your home folder)
set_workspace(path=None)

# login credentials
insta_username = 'Bradscanvas'
insta_password = 'password'

# restriction data


session = InstaPy(username=insta_username,
                  password=insta_password,
                  headless_browser=False,
                  disable_image_load=True)
                  
with smart_run(session):

        session.set_mandatory_language(enabled=True, character_set=['LATIN'])        
        session.set_quota_supervisor(enabled=True, sleep_after=["follows", "server_calls"],
                                     sleepyhead=True,
                                     stochastic_flow=True,
                                     notify_me=True,
                                     peak_follows_hourly=18,
                                     peak_follows_daily=None,
                                     peak_unfollows_hourly=26,
                                     peak_unfollows_daily=None,
                                     peak_server_calls_hourly=188,
                                     peak_server_calls_daily=4200)
        
        session.set_simulation(enabled=True, percentage=73)
        session.set_action_delays(enabled=True,
                                  follow=16.88,
                                  unfollow=14.91,
                                  randomize=True,
                                  random_range_from=214,
                                  random_range_to=447)
                
        session.set_relationship_bounds(enabled=True,
                                        potency_ratio=1.12,
                                        delimit_by_numbers=True,
                                        max_followers=46880,
                                        max_following=26880,
                                        max_posts=1000,
                                        min_posts=6,
                                        min_followers=6,
                                        min_following=6)
        
        session.set_skip_users(skip_private=True, private_percentage=74,
                               skip_no_profile_pic=True, no_profile_pic_percentage=100,
                               skip_business=True)

        session.set_user_interact(amount=5, randomize=True, percentage=50, media='Photo')
        session.set_do_follow(enabled=True, percentage=70)
        session.set_do_like(enabled=True, percentage=100)
        session.interact_user_followers(['emjeiiamira', 'aquabumps', 'josh_burkinshaw', 'scottydman'], amount=50, randomize=True)

Duplicate issue #5001: Connection refused (Pi3 and Firefox)
Created: 2019-09-03T20:40:49Z
Last update of everything, not working on Pi3.
Error message:
InstaPy Version: 0.6.2
 ._.  ._.  ._.  ._.  ._.  ._.  ._. 
Workspace in use: "/root/InstaPy"
Traceback (most recent call last):
  File "z_debug.py", line 5, in <module>
    from z_instabot import *
  File "/home/pi/InstaPy/z_instabot.py", line 16, in <module>
    bypass_security_challenge_using='sms')
  File "/root/.local/lib/python3.5/site-packages/instapy/instapy.py", line 321, in __init__
    self.logger,
  File "/root/.local/lib/python3.5/site-packages/instapy/browser.py", line 114, in set_selenium_local_session
    options=firefox_options,
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  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.WebDriverException: Message: connection refused

My attempts to fix it:
sudo pip3 install -U $(pip3 freeze | cut -d '=' -f 1)
sudo apt install tmux build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev -y
sudo nano /etc/dphys-swapfile
there I set: CONF_SWAPSIZE=500
Then activate swapping: sudo systemctl start dphys-swapfile
In addition have it start automatically: sudo systemctl enable dphys-swapfile
Finally, try to run the script:
sudo xvfb-run python3 quickstart.py
I get the same error.
Anybody knows how to fix it? Seems to run ok on Ubuntu.

Closing comment (2019-09-09T12:02:47Z): After a reboot and a second attempt, this is what I get:
INFO [2019-09-09 13:59:10] [XXX]  Getting XXX image list...
Traceback (most recent call last):
  File "/home/pi/InstaPy/z_instabot.py", line 328, in interact_by
    randomize=True)
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 5540, in interact_by_comments
    self.user_interact_media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/instapy.py", line 2471, in interact_by_users
    media,
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/like_util.py", line 450, in get_links_for_username
    browser, "profile", username, person, None, logger, logfolder
  File "/home/pi/.local/lib/python3.7/site-packages/instapy/unfollow_util.py", line 211, in get_following_status
    following_status = follow_button.text
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
    return self._execute(Command.GET_ELEMENT_TEXT)['value']
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed

Edit: Still getting this error after trying a few suggested fixes on git
Message: The element reference of <button class="_5f5mN       jIbKX  _6VtSN     yZn4P   "> is stale;
either the element is no longer attached to the DOM, it is not in the current frame context, or the
document has been refreshed.

Related to #5039