basically I try to write a code that automatically clicks the cookie and, every 3 seconds, buys an item of the found elements without the class-attribute of "grayed" (as those are the ones u dont have enough cookies to buy for) Angela Yu made it pretty complicated with checking cookies vs a dict consisting of nested lists with "id" and "price" etc. but I thought I could make this shorter... any help? code works fine until first item is bought, then I get the "stale element reference: stale element not found in the current frame" error
heres the code:
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time
options = Options()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options)
driver.get("https://orteil.dashnet.org/experiments/cookie/")
big_cookie = driver.find_element(By.ID, "cookie")
store = driver.find_elements(By.CSS_SELECTOR, "div #store div")
item_ids = [item.get_attribute("id") for item in store]
timeout = time.time() + 3
while True:
big_cookie.click()
if time.time() > timeout:
for element in store:
if element.get_attribute("class") == "grayed":
pass
else:
element.click()
timeout = time.time() + 5