BobBobbingson
BobBobbingson

Reputation: 13

Is it possible to find an element using multiple words using By.CLASS_NAME in selenium python?

I am working on a browser bot and have encountered a problem. Every documentation has an example where an element is found(by class_name) using only one string that represents a class. My problem is that I want to use more than one string(more than one word) to find a class(to be more specific). Here is what every example shows:

browser.find_element(By.CLASS_NAME, "text-orange-400")

And here is what I want to do:

browser.find_element(By.CLASS_NAME, "text-orange-400 transition hover:opacity-70")

Is it possible to do so?

I have tried using many torturous and outrageous ways that I have no intensions in listing in this post. So just help me pls.

Upvotes: 0

Views: 71

Answers (1)

Prophet
Prophet

Reputation: 33361

No.
To locate element based on multiple class name values you should use CSS Selector or XPath.
CSS_Selector:

browser.find_element(By.CSS_SELECTOR, ".text-orange-400.transition.hover:opacity-70")

XPath

browser.find_element(By.XPATH, "//*[@class='text-orange-400 transition hover:opacity-70']")

Upvotes: 1

Related Questions