python - 如何使用 Selenium 点击按钮?

标签 python 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()

关于python - 如何使用 Selenium 点击按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220902/

相关文章:

python - MySQL python : Cursor returns the variable name

c++ - Boost::python - 在 python 类的对象上填充指针的 C++ vector

python - 使用 python 进行 Elasticsearch 按时间戳排序

java - Cucumber 特征文件不识别步骤

selenium - 将 WebDriver promise 转换为 native promise ?

python - 为什么在 while 循环中尝试覆盖变量时会出现内存错误? (Python)

python - 在 PyTorch 中使用 module.to() 移动成员张量

python - 如何在Python中使用selenium在弹出身份验证窗口时自动登录

python - XPath:查找包含文本 X 而不是 Y 的元素

python - 多处理和 Selenium Python