0

I'm trying to create a bot that auto clicks the cookie and auto buys upgrades. Sometimes the bot runs 40 sec then I get the error above and sometimes it take only few seconds.

I'll be glad to know what im doing wrong.

My code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
import time

service = Service("C:\Development\chromedriver.exe")
driver = webdriver.Chrome(service=service)

driver.get("http://orteil.dashnet.org/experiments/cookie/")

cookie = driver.find_element(By.ID, "cookie")

store = driver.find_element(By.ID, "store")

timeout = time.time() + 5
five_min = time.time() + 60 * 5

while True:
    cookie.click()

    if time.time() > timeout:
        objects = store.find_elements(By.CSS_SELECTOR, "div b")
        prices = []

        for item in objects:
            prices.append(item.get_attribute("textContent").split(" - "))

        for item in prices:
            item[1] = item[1].replace(",", "")

        prices.reverse()
        prices.pop(0)

        money = int(driver.find_element(By.ID, "money").get_attribute("textContent").replace(",", ""))

        for item in prices:
            if money >= int(item[1]):
                obj = driver.find_element(By.ID, f"buy{item[0]}")

                #This is the part when i get the error, usually after buying one uprgade.
                obj.click()
        timeout = time.time() + 5

     #The bot should run only 5 min then break with the corresponding message.
    if time.time() > five_min:
        cookie_per_s = driver.find_element(By.ID, "cps").get_attribute("textContent")
        print(cookie_per_s)
        break

0 Answers0