I am working on a Game Playing Bot for Cookie Clicker game. The bot clicks the cookie and buys the items automatically. You would understand what the bot does once you try the game yourself. Link: https://orteil.dashnet.org/experiments/cookie/
Problem: Keep getting this exception within seconds of its execution:
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found
(Session info: chrome=114.0.5735.198)
Now I tried executing this multiple times and it crashed at different intervals of time. I even recoded the entire project after multiple executions. From what I understood online, this happens when there's an update in the browser or any user interation during the execution. But I did not touch my keyboard during the execution. Here's the code:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get(url="http://orteil.dashnet.org/experiments/cookie/")
clicker = driver.find_element(By.XPATH, '//*[@id="cookie"]')
while True:
clicker.click()
money = int(driver.find_element(By.XPATH, '//*[@id="money"]').text)
cursor_price = int(driver.find_element(By.XPATH, '//*[@id="buyCursor"]/b').text.split()[-1])
if money > cursor_price:
driver.find_element(By.XPATH, '//*[@id="buyCursor"]/b').click()
Should I try using a different browser?