【问题标题】:Writing the xpath for the below code为以下代码编写 xpath
【发布时间】:2017-12-06 20:08:37
【问题描述】:

下面是我的一个项目的代码 sn-p,我需要某个元素的 xpath。

<div class="panel panel-default">
   <div class="panel-body">
      <div class="row">
         <div class="col-md-5 text-right boldText">Service Group Id:</div>
         <div class="col-md-5 ng-binding">436095</div>
      </div>
   </div>
</div>

我需要 436095 元素的 xpath。但是,其他一些元素的类是相同的,所以我不能使用相同的,文本也不同。所以我想要一个通用的解决方案并将 xpath 用作

//div[contains(text(),"Service Order Id:")]/../div[2]

但这不起作用。请给我一个更好的解决方案。

【问题讨论】:

    标签: html xpath


    【解决方案1】:

    首先,文字是Service Group Id,而不是Service Order Id。而且,您可以使用following-sibling notation

    //div[contains(., "Service Group Id")]/following-sibling::div
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用以下 xpath。它会为你工作。

      //div[@class='row']/child::div[2]
      //div[@class='col-md-5 text-right boldText']/following-sibling::div    
      //div[contains(.,'Service Group Id:')]/following-sibling::div
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-02-06
        • 2021-01-10
        • 2019-08-19
        • 1970-01-01
        • 2016-08-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多