Reputation: 35
I'm trying to find a button to click using Selenium. The portion of html containing the button is the following:
<button class="btn-standard call-to-action">Login</button>
I am trying to find it with:
btn = driver.find_element_by_css_selector("btn-standard.call-to-action")
And then i should execute btn.click()
But when i try to run the code i get this error:
no such element: Unable to locate element: {"method":"css
selector","selector":"btn-standard.call-to-action"}
How can I fix this?
Upvotes: 0
Views: 463
Reputation: 3355
Try this
btn = driver.find_element_by_css_selector(".btn-standard.call-to-action")
You are missing a dot at the beginning of css_selector so it looks for an element btn-standard
and not a class. And there is no such element as btn-standard
Also you can try element type with class like so:
btn = driver.find_element_by_css_selector("button.btn-standard")
Or any mix of class and element type
Upvotes: 1
Reputation: 333
You can even use xpath:
btn = driver.findElement(By.xpath("//button[contains(text(),'Login')]"))
Upvotes: 1
Reputation: 41
For css selectors '.' is appended in the beginning only for class. Can you try this:
btn = driver.find_element_by_css_selector("button.btn-standard")
Upvotes: 0