简体   繁体   English

确定xpath时遇到问题

[英]Having problems determining xpath

This one has me stumped. 这个让我难过。 Usually I will use the Firebug feature to obtain the xpath for me but this time it doesn't seem to be working. 通常,我将使用Firebug功能为我获取xpath,但是这次似乎不起作用。

We have a US and UK version of our website. 我们有我们网站的美国和英国版本。 Firebug's xpath works on the US version but not on the UK version. Firebug的xpath在美国版本上有效,但在英国版本上无效。 If I grab the xpath using Firebug it's the exact same xpath for both sites but it works on the US version of the site and fails on the UK version of the site. 如果我使用Firebug抓取xpath,则这两个站点的xpath完全相同,但是它在该站点的美国版本上有效,而在该站点的英国版本上无效。

Here is the HTML: 这是HTML:

 <a class="ng-scope" ng-click="flightSearch.sort.$select(featuredItinerary.sortOrder)" tooltip="">
    <h3 class="ng-binding">Fastest</h3>
       <div class="row sort-block-row">
       <div class="col-xs-12">
            <h2 class="ng-binding">$283</h2>
       </div>

I want to capture the value of the $283. 我想获取283美元的价值。 This value will change constantly. 该值将不断变化。

Here is what Firebug is telling me the xpath value is: 这是Firebug告诉我的xpath值是:

 //html/body/div[2]/main/div/ui-view/ui-view/section/div/div[2]/div/ul/li[2]/a/div/div[1]/h2

Anyone have a better xpath value I can try and hope it works for both sites? 任何人都有更好的xpath值,我可以尝试并希望它对两个站点都适用?

以下xpath应该能够帮助获取所需的值:

//a/h3[text()='Fastest']/descendant::h2

Try any of these below xpath 尝试以下xpath任何一种

Assuming You are going to access the Fastest price. 假设您要访问Fastest价格。

Explanation: Start your xpath with <h3> tag using text method to match text as Fastest . 说明:使用text方法以<h3>标记启动xpath,以将text匹配为Fastest Then move ahead with <h2> tag using following keyword. 然后使用following关键字继续<h2>标记。 Because your <h2> tag is consider price. 因为您的<h2>标签是考虑价格的。

//h3[contains(text(), 'Fastest')]/following::h2

OR 要么

Explanation: Use class attribute of <div> tag. 说明:使用<div>标记的class属性。 Then move ahead with <h2> tag. 然后继续使用<h2>标签。 Because your tag is consider price. 因为您的标签是考虑价格。

//div[@class='col-xs-12']/h2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM