繁体   English   中英

如何点击Selenium按钮?

[英]How to click on a button with Selenium?

我正在尝试使用Python Selenium API来单击按钮。 HTML代码如下:

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

如何最好地识别这个元素? 我正在尝试以下代码

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

但是得到了一个错误

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

我还能做些什么来选择这个元素?

如果类名值包含空格,则不能使用find_element_by_class_name() 尝试:

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

您也可以使用css选择器

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM