【问题标题】:How to locate an element with preceding-sibling?如何定位具有前同级元素的元素?
【发布时间】:2022-01-25 22:29:45
【问题描述】:
<a href="/pro/2/len.html" class="lol-link" href="/pro/2/len.html"> <span hide="trololo"> <img class="prod" ng-src="https://med.png" alt="Len" src="https://med.png"> </span> <span ng-hide="index" class="ng-hide"> <span>Len</span> </span> </a>

我的 xpath:

"//span[contains(text(), 'Len')]/preceding-sibling::span"

我想找到文本“Len”,但不幸的是我的 xpath 不起作用。有人可以帮忙吗?

【问题讨论】:

  • 在我看来像 //span[.='Len'],但也许有什么你没有告诉我们的?
  • //a[@class="lol-link"]/span[2]/span,在此超链接之前可能还有更多内容。
  • @simpleApp,@MichaelKay 不起作用。我试过//span[contains(@class,'ng-hide')]/preceding-sibling::span 并且它有效,但我不知道如何到达'Len'
  • 我想定位文字'Len',但在什么条件下?

标签: python selenium xpath


【解决方案1】:

你可以试试:

//span[span="Len"]/span

【讨论】:

    猜你喜欢
    • 2022-10-07
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多