【发布时间】:2019-07-30 02:37:57
【问题描述】:
Chrome 中的 xpath 表达式 $x("//button[text() = 'Got it']") 返回两个按钮元素,但页面中只有一个这样的按钮。
就数据而言,这两个元素看起来相同。
使用 selenium 和 python 有时可以单击数组的第二个元素,但多次返回 Element is not interactable 错误。
任何指针?
<button class="button slim-large" ng-click="ctrl.closeDialog()">Got it</button>
添加此代码来处理重复按钮的情况,其中一个可见而另一个不可见。
button_clicked = False
elems = self.find_all_by_xpath(locator="//button[contains(text(),'Got it')]")
for elem in elems:
if elem.is_displayed():
elem.click()
button_clicked = True
if button_clicked == False:
print("None of " + str(len(elems)) + " buttons are click-able")
谢谢, 萨米尔
【问题讨论】:
-
请分享您的网址。
-
页面中只有一个这样的按钮你是基于浏览器中页面的视觉外观,还是基于实际的html源代码?
-
@Winner 抱歉我不能分享网址
-
@NarendraR 这是标记。
<button class="button slim-large" ng-click="ctrl.closeDialog()">Got it</button> -
这个
//button[text() = 'Got it'][@class='button slim-large']怎么样?
标签: python selenium google-chrome xpath