Home > OS >  Selenium won't find my element by class name (Python)
Selenium won't find my element by class name (Python)

Time:09-28

Fist of all here is the picture of the HTML code: HTML

This is the element I tried to access: Class

I tried: driver.find_element_by_class_name("btn_green_white_innerfade btn_medium market_commodity_buy_button")

... but it threw up an error. Error Code

I would be glad for any help!
Regards
-Eirik

CodePudding user response:

In Selenium, class name do not have support for spaces. Please remove spaces and put . instead to make a css_selector.

Instead of

driver.find_element_by_class_name("btn_green_white_innerfade btn_medium market_commodity_buy_button")

do this :

driver.find_element_by_css_selector("a.btn_green_white_innerfade.btn_medium.market_commodity_buy_button")

CodePudding user response:

Compound class names are not permitted in Selenium. Locates elements whose class name contains the search value. i.e. you won't be able to pass multiple class names. If you pass multiple class names then you will get compound class name exception.

Wrong way:

By.className("alert alert-class")

Right way:

By.className("alert.alert-class")

  • Related