【问题标题】:Python selenium (html) checkboxPython 硒 (html) 复选框
【发布时间】:2020-07-16 14:23:31
【问题描述】:

我尝试使用普通的.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>

【问题讨论】:

  • 您能否提供更多详细信息:1.您到底尝试了什么(最小可重现示例)? 2. 发生了什么?什么不起作用?
  • 我正在尝试自动执行一项任务,因为我需要它来选择搜索栏并在搜索名称后搜索名称单击复选框以确认一切正常,直到搜索名称部分但一旦单击复选框以选择名称,它就会给我一个错误,我正在使用 .click 函数单击按钮
  • 为什么不使用按钮类 'dCJp8' driver.find_element_by_class_name('dCJp8').click() ?

标签: python html python-3.x selenium automation


【解决方案1】:

你有一个动态元素。

您需要使用不变的部分:

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

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

见上午https://www.tutorialspoint.com/how-to-use-regular-expressions-in-xpath-in-selenium-with-python

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2020-05-11
    • 2019-10-13
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多