This is the page of users who have liked a post on Instagram:
I get them all by id in a list:
LikeSourcePage_RowUserName = driver.find_elements(By.ID, Read_Config('Locator-LikeSourcePage', 'LikeSourcePage_RowUserName'))
And I run a for loop on this list and…
What I want to do is log into each account one by one, then go back and log into the next user account in my list, but when I go back I get the following error:
selenium.common.exceptions.StaleElementReferenceException: Message: Cached elements 'By.id: row_user_primary_name' do not exist in DOM anymore
This is my complete code:
actions = TouchAction(driver)
if Checking_The_Existence_Of_An_Element(Time = 60, By_1 = By.ID, Code_1 = Read_Config('Locator-LikeSourcePage', 'LikeSourcePage_RowUserName')) == True:
LastUserIdInLoop = []
while True:
LikeSourcePage_RowUserName = driver.find_elements(By.ID, Read_Config('Locator-LikeSourcePage', 'LikeSourcePage_RowUserName'))
for UserID in LikeSourcePage_RowUserName:
Username = UserID.text
if Username not in DF_Main_The_Database_Of_AllUsers(read_or_write = 'read')['Username'].values:
DF_Main_The_Database_Of_AllUsers(read_or_write = 'write', value = Username)
print(Username)
actions.tap(UserID).perform()
time.sleep(10)
ActionBarButtonBack = driver.find_element(By.ID, Read_Config('Locator-PageUser', 'PageUser_ActionBarButtonBack'))
actions.tap(ActionBarButtonBack).perform()
LastUserIdInLoop.append(Username)
Swipe_Random(Scroll_Position = None)
time.sleep(random.randint(1, 3))
if len(LastUserIdInLoop) >= 2:
if (LastUserIdInLoop[-1] == Username) and (LastUserIdInLoop[-2] == Username):
break
And this is the complete error message I get:
Traceback (most recent call last):
File "/Robots-Instagram-with-Appium/RobotCore.py", line 1042, in <module>
Run_Robot_Instagram(AVD_Name = 'Group_00_InstaAcc-Device_A')
File "/Robots-Instagram-with-Appium/RobotCore.py", line 1027, in Run_Robot_Instagram
RandomBehavior4Actions_And_ManageLikeResources()
File "/Robots-Instagram-with-Appium/RobotCore.py", line 825, in RandomBehavior4Actions_And_ManageLikeResources
Username = UserID.text
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 76, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/appium/webdriver/errorhandler.py", line 31, in check_response
raise wde
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/appium/webdriver/errorhandler.py", line 26, in check_response
super().check_response(response)
File "/Users/amir/opt/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: Cached elements 'By.id: row_user_primary_name' do not exist in DOM anymore