如何让 selenium 通过 HTML 中的属性识别按钮并在 python 中只要有可能就自动点击它

How to make selenium identify a button through an attribute within the HTML and click on it automatically whenever it is possible in python

是否可以让 selenium 识别 html 按钮属性并单击它。因此,只要它找到一个按钮属性,它就会自动点击它。因为我总是需要预测下一个按钮出现和设置需要多长时间 time.sleep() 但很多时候它会导致错误。

当然,可以通过属性识别 html 按钮并使用 在其上调用 click()

但是,只要通过它的属性找到一个按钮,它就可以自动点击它是不可能的:

  • 预测等待下一个按钮可点击的时间应该是您的测试计划测试架构的一部分,并且应该是 .
  • 的一部分
  • 此外,使用 time.sleep(n) 违背了自动化 的目的,应不惜一切代价避免使用。

    You can find a relevant detailed discussion in

  • 理想情况下,您需要删除所有出现的 time.sleep(n) 导致 WebDriverWait inconjunction with the expected_conditions

    You can find a relevant detailed discussion in