Reputation: 63
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.
Upvotes: 1
Views: 47
Reputation: 44013
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)
Upvotes: 1