1

So im trying to automate the cookie clicker game here https://orteil.dashnet.org/cookieclicker/ but Im having a problem purchasing the upgrades Here is some code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.implicitly_wait(5)
driver.maximize_window()
driver.get("https://orteil.dashnet.org/cookieclicker/")

cookies_count = driver.find_element_by_id("cookies")
cookie = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.ID, "bigCookie"))
)
items = [driver.find_element_by_id("productPrice" + str(i)) for i in range(1, -1, -1)]
while True:
    cookie.click()
    count = int(cookies_count.text.split(" ")[0])
    for item in items:
        value = int(item.text)
        if value <= count:
            WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, item))).click()

After I reach 17/18 cookies it stops with no error and my explict wait times out.

1 Answer 1

1

The item is not directly "clickable" because the browser thinks another element is covering it. So you have to use JavaScript to directly click it:

Replace:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, item))).click()

With:

driver.execute_script("arguments[0].click();", item)
Sign up to request clarification or add additional context in comments.

2 Comments

But is there another way doing it directly with python?
Not that I am aware of. Take a look at this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.