【问题标题】:Locate first element if it has multiple number of same text [duplicate]如果第一个元素有多个相同的文本,则找到它[重复]
【发布时间】:2019-09-08 11:48:54
【问题描述】:

我有 4 个与“HOD”同名的文本,我想点击第一个“HOD”。

我已经尝试了所有这些: 1.//a[包含(文本(),'HOD')][1] 2.//a[@class="link_job ng-binding"][1]

<ul type="none" class="job-search-results ng-scope" ng-if="flag &amp;&amp; flag != undefined" id="ulId" ng-repeat="j in jobResult" xpath="1">
        <!-- ngIf: j.statusId == 1 --><li ng-if="j.statusId == 1" class="job-small ng-scope"><a href="" class="big-a"></a><a href="" ng-click="fetchJobById(j.id);insertRecentSearch(j.position.id,'aaa')" class="link_job ng-binding">HOD</a>
              <div class="ng-binding"><b>Department:</b> Computer_Science</div>
              <div><b>Job Summary:</b> <p class="ng-binding">HOD should own masters degree in their onw field.
                    </p>
              </div>

            <img ng-src="resources/img/logo-placeholder.png" style="height:64px;" src="resources/img/logo-placeholder.png">
            <!-- ngIf: j.status == 'Applied' -->
        </li><!-- end ngIf: j.statusId == 1 -->

        <!-- ngIf: j.statusId !=1 -->

      </ul>

I expect that it should click on first HOD text.

【问题讨论】:

  • 当你尝试的时候发生了什么?
  • 未知错误:元素 ... 在点 (622, 402) 是不可点击的。其他元素会收到点击:
  • 当您尝试点击您的链接时,您的页面加载完成了吗?
  • 通过使用相对的 xpath 我可以 clcik 它..但它不能通过我自己的 xpath 工作
  • 是的,我使用了 time.delay(10) 并且它成功了,感谢两者

标签: selenium-webdriver


【解决方案1】:

虽然设置延迟会有所帮助,但这并不是最好的方法。您可以等到您的加载不可见,然后尝试单击。这是一个快速的方法:

driver.wait(until.ElementIsNotVisible(driver.findElement(By.css('.loader'))));
driver.findElement(By.xpath('//a[contains(text(),'HOD') ][1]')).click();

【讨论】:

  • 感谢您的建议
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多