'Selenium - get a number as a value

That is my code:

chrome_driver_path = 'C:\Development\chromedriver.exe'
driver = webdriver.Chrome(chrome_driver_path)
driver.get('https://orteil.dashnet.org/cookieclicker/')

button = driver.find_element_by_css_selector('#bigCookie')
driver.implicitly_wait(5)

my_path = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[19]/div[3]/div[6]/div[2]')
content = my_path.get_attribute('div')
print(content)

What I would like to do, is I would like to get a number shown in the picture below:enter image description here

Now I tried to get that number with the ".text" method but then I searched and realized that I cant use it because it's not an actual value. I tried to convert it into an int so that I can use it. I found the get_attribute method( shown in the linked code how I used it ), but no matter if I try to pass in as a value the span, div, id, or class name it returns none.

My question is how can I get that number( shown in the picture ) to get it as a value so that I can use it as an int?



Solution 1:[1]

There are several issues here:

  1. You are looking on a wrong element
  2. You have to improve locators
  3. To get the element text you can to use .text
    Something like this will work better:
the_text = driver.find_element_by_xpath("//div[@id='productIconOff0']/..//span[@id='productPrice0']").text

Solution 2:[2]

I found the solution, it was quite simple. I needed to wait before I would open what I wanted as this element that I wanted to select only appear when I have x amount of coin.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Robin Gergelyfi