Element exists but Selenium says it doesn't

Viewed 264

I'm trying to print text from a class with this code:

price = driver.find_element_by_class_name("text-robux-lg wait-for-i18n-format-render").text
print(price)

But selenium says that the class text-robux-lg wait-for-i18n-format-render doesn't exist and then gives me this error code:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".text-robux-lg wait-for-i18n-format-render"}

Is there any fix to this or is it a problem with the site?

2 Answers

The element you are trying to access having several class names. Some of them are dynamic, not fixed while this text-robux-lg is fixed and unique so you can use it along.
Like the following:

price = driver.find_element_by_css_selector("span.text-robux-lg").text
print(price)

It would be better if you provide the snippet of the HTML element.

Anyway, if you target elements with multiple classes, you should use xpath or css selector. Here I assume it is a div element:

price = driver.find_element_by_css_selector("div[class='text-robux-lg wait-for-i18n-format-render']").text
Related