【发布时间】:2020-09-19 17:00:54
【问题描述】:
我正在尝试在 python 中使用 selenium 查找网站中的按钮,并且按钮标识为: AB 12
我正在尝试使用此代码,但都找不到按钮...
driver.find_element_by_xpath("//button[contains(@class, '.size-grid-dropdown .size-grid-button') and contains(.,'AB 12)]")
driver.find_element_by_xpath('//button[span[text()="AB 12"]')
driver.find_element_by_link_text("AB 12")
问题是:我有很多相同类别但 AB 12 / AB 23 / AB 34 不同的按钮...
如何找到精确的按钮?
谢谢!
【问题讨论】:
-
能否请您发布 DOM 屏幕截图。这样我们也可以尝试检查其他一些属性。
-
find all by class=> 你会得到一个按钮列表 => 循环遍历 => 检查文本是否为 "AB 12" 。根据您提供的 DOM,按钮没有其他唯一标识
-
//button[text()="AB 12"]有效吗?这是您尝试的第二个的修改版本,没有跨度。
标签: python html selenium class button