【问题标题】:How do I identify these buttons using python selenium?如何使用 python selenium 识别这些按钮?
【发布时间】:2019-09-22 12:20:24
【问题描述】:

所以这些蓝色按钮在配置文件旁边带有十字,我如何编写一行代码来返回所有这些按钮的列表。

类似:

buttons = browser.find_element_by_css_selector("something here")

buttons = browser.find_elements_by_xpath("something here")

或者其他什么 find_elements_by_... 有效

【问题讨论】:

  • 请不要张贴html图片。使用通过edit 提供的 sn-p 工具

标签: python selenium selenium-webdriver selenium-chromedriver webautomation


【解决方案1】:

我看到有多个按钮大多具有相同的类,所以你必须使用

然后遍历所有这些。

这里是xpath

buttons = driver.find_elements_by_xpath("//span[@class='ui_button_icon']")
for button in buttons:
    button.click()    

如果你想点击特定按钮,你可以使用索引或相对按钮到其他元素,如人名。

# clicking on 2nd button
driver.find_element_by_xpath("(//span[@class='ui_button_icon'])[2]").click()

这是css

span.ui_button_icon

您可以使用 nth-of-type 应用相同的逻辑来单击第 n 个元素。

【讨论】:

  • 如果您认为此问题已解决,请接受答案,以便我们减少未回答问题的数量 :-)
猜你喜欢
  • 2019-09-21
  • 2022-01-28
  • 2019-09-24
  • 1970-01-01
  • 2016-08-19
  • 2021-06-25
  • 2016-12-03
  • 1970-01-01
  • 2023-04-06
相关资源
最近更新 更多