Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Selenium单击按钮?_Python_Selenium - Fatal编程技术网

Python 如何使用Selenium单击按钮?

Python 如何使用Selenium单击按钮?,python,selenium,Python,Selenium,我试图使用Python Selenium API来单击按钮。HTML代码如下所示: <button class="btn wizard-next btn-primary" type="button">Weiter</button> 但我犯了一个错误 selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitt

我试图使用Python Selenium API来单击按钮。HTML代码如下所示:

<button class="btn wizard-next btn-primary" type="button">Weiter</button>
但我犯了一个错误

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

我还可以做些什么来选择此元素?

如果类名值包含空格,则不能使用
按类查找元素()。
尝试:


您也可以使用css选择器

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

即使在同一页面上还有另一个按钮,我也可以使用它吗?在这种情况下,您必须更具体地了解元素css选择器。例如,如果它是一个表单,那么您可以将其更改为
driver。通过css\u选择器(“div#formID>btn”)查找元素。单击()
这样您就不会单击页面上的其他元素
driver.find_element_by_xpath("//button[@class='btn wizard-next btn-primary']").click()
driver.find_element_by_css_selector("btn").click()