How to click on a button with Selenium?

▼魔方 西西 提交于 2021-02-07 04:31:24

问题


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?


回答1:


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()



回答2:


You can use css selector also

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


来源:https://stackoverflow.com/questions/38220902/how-to-click-on-a-button-with-selenium

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!