Alex
Alex

Reputation: 44405

How to click on a button with Selenium?

I am trying to use the Python Selenium API in order to click on a button. The HTML code is as follows:

<button class="btn wizard-next btn-primary" type="button">Weiter</button>

How to best identify this element? I was trying the following code

driver.find_element_by_class_name("btn wizard-next btn-primary").click()

but got an error

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted

What else can I do to select this element?

Upvotes: 1

Views: 795

Answers (2)

Ranjith&#39;s
Ranjith&#39;s

Reputation: 4740

You can use css selector also

driver.find_element_by_css_selector("btn").click()

Upvotes: 0

Andersson
Andersson

Reputation: 52685

You cannot use find_element_by_class_name() if class name value contains spaces. Try:

driver.find_element_by_xpath("//button[@class='btn wizard-next btn-primary']").click()

Upvotes: 3

Related Questions