首页 > 解决方案 > Python 硒 (html) 复选框

问题描述

我尝试使用普通命令单击此按钮,.click()但它不起作用

并且在手动点击它之后,类从这个“ glyphsSpriteCircle__outline__24__grey_2 u-__7”变为这个“ glyphsSpriteCircle_check__filled__24__blue_5 u-__7”怎么办?

<button class="dCJp8">
  <span aria-label="Toggle selection" class="glyphsSpriteCircle__outline__24__grey_2 u-__7"></span>
</button>

标签: pythonhtmlpython-3.xseleniumautomation

解决方案


你有一个动态元素。

您需要使用不变的部分,例如:

或者您可以对静态的部分使用正则表达式,例如

driver.find_element_by_xpath("//span[contains(@class,'glyphsSpriteCircle')]")

请参阅https://www.tutorialspoint.com/how-to-use-regular-expressions-in-xpath-in-selenium-with-python


推荐阅读