"ValueError: invalid literal for int() with base 10: '1,077'" when using a cookie clicker bot I made with a youtube tutorial


So I followed the tutorial by Techwithtim on Youtube and started running the script (it uses python and selenium). It worked for a while and then I got the Error: "ValueError: invalid literal for int() with base 10: ‘1,077’"

My code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time

PATH = r"C:\Users\Leander\Documents\scraping\chromedriver.exe"
driver = webdriver.Chrome(PATH)


cookie = driver.find_element_by_id("bigCookie")
cookie_count = driver.find_element_by_id("cookies")
items = [driver.find_element_by_id("productPrice" + str(i)) for i in range(1,-1,-1)]

actions = ActionChains(driver)
for i in range(1000000):
    count = int(cookie_count.text.split(" ")[0])
    for item in items:
        value = int(item.text)    #cmd tells me the error is right here
        if value <= count:
            upgrade_actions = ActionChains(driver)

I think it might be because of the "items = [driver.find_element_by_id("productPrice" + str(i)) for i in range(1,-1,-1)]"-line because I don’t completly understand what it does (the "in range" bit).

It might be helpful to know that the third upgrade costs 1100 cookies so it crashed right before reaching that mark. Upgrades 1 and 2 went fine for multiple times.
If you need more information, just ask about it.

Thanks for your help!


The string "1,077" is invalid integer. Try to remove ,:

value = int(item.text.replace(',', ''))

Answered By – Andrej Kesely

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published