I have division with class ="viewSaveDietData" that contains spans with same class name. I am not able to differentiate the XPATHS of the different spans. Please tell me the XPATH of the individual spans..
我有class =“viewSaveDietData”的分区,它包含具有相同类名的跨度。我无法区分不同跨度的XPATHS。请告诉我个人跨度的XPATH ..
<div class="viewSaveDietTitle" >Created By:</div><div class="viewSaveDietData" ><span class="Answer"><b style='color:#386AA1;'><a href="/www/community/ProfileWall.aspx?f=FitClick" title="FitClick">FitClick</a></b> on Jan 27, 2012</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Users:</div><div class="viewSaveDietData" ><span class="Answer">3,403 (<a href="/online_weight_loss_support?cdID=23982">Find someone using this diet</a>)</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Comments:</div><div class="viewSaveDietData" ><span class="Answer"><a href="#jump-to-comments">Be the first!</a></span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Diet Category:</div><div class="viewSaveDietData" ><span class="Answer">Balanced</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Diet Plan Length:</div><div class="viewSaveDietData" ><span class="Answer">Ongoing</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Meals Per Day:</div><div class="viewSaveDietData" ><span class="Answer">3 meals, 4 meals, 5 meals, 6 meals</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Target Gender:</div><div class="viewSaveDietData" ><span class="Answer">Women and men</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Weight Goal:</div><div class="viewSaveDietData" ><span class="Answer">Lose weight, Maintain weight, Gain weight</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Cooking Difficulty:</div><div class="viewSaveDietData" ><span class="Answer">Easy</span></div>
<div style="clear:both;"></div>
<div class="viewSaveDietTitle" >Tags:</div><div class="viewSaveDietData" ><span class="Answer">52.5:22.5:25 Macronutrient Ratio</span></div>
<div style="clear:both;"></div>
I want to get the xpath of "Balanced"
我想得到“平衡”的xpath
3 个解决方案
#1
0
I'm not sure I understood your question, but it sounds like you're looking for something like
我不确定我理解你的问题,但听起来你正在寻找类似的东西
//div[@class='viewSaveDietTitle'][. = 'Diet Category']/
following-sibling::div[1][@class='viewSaveDietData']/span/text()
This will select the text of the span that's a child of the div whose class is viewSaveDietData
, which immediately follows a div containing the title string 'Diet Category'. In other words, my understanding of your question is, how to select a particular span based on the title of the associated div
.
这将选择跨度的文本,该跨度是div的子节点,其类是viewSaveDietData,紧跟在包含标题字符串'Diet Category'的div之后。换句话说,我对您的问题的理解是,如何根据相关div的标题选择特定范围。
If you just want to select a span based on its order in the document, you could use
如果您只想根据文档中的顺序选择范围,则可以使用
(//span[@class = 'Answer'])[4]
#2
0
Some ways that I just tested (via the firefox selenium plugin and also the firefox xpath plugin) are:
我刚刚测试过的一些方法(通过firefox selenium插件以及firefox xpath插件)是:
//div[@class="viewSaveDietData"]/span[contains(text(), "Balanced")]
Also (more specificly):
(更具体地说):
//div[@class="viewSaveDietData"]/span[contains(@class, 'Answer') and text()="Balanced"]
Just by position with:
只需按位置:
//div[@class="viewSaveDietData"][4]/span
By Answer span alone (doesn't depend on being in the div) with
通过单独的答案范围(不依赖于在div中)
//span[contains(@class, 'Answer') and text() = "Balanced"]
(or more simply)
(或更简单地说)
//span[@class="Answer" and text()="Balanced"]
So:
所以:
//div[@class="viewSaveDietData"]/span[contains(@class, 'Answer') and text()="Balanced"]
is most specific which of course means it's most likely to be specific in selecting the desired elements but also will be more affected by page changes.
是最具体的,当然这意味着它最有可能在选择所需的元素时具体,但也会受到页面更改的影响。
#3
0
Got something similar to Larsh, but using /*/ instead of // as this makes search quicker. If titles are unique and if you are interested in answer for Diet Category the below code or one from LarsH should be good.
有类似于Larsh的东西,但使用/ * /而不是//因为这会使搜索更快。如果标题是唯一的,如果你有兴趣回答饮食类别,下面的代码或LarsH的代码应该是好的。
/*/div[@class="viewSaveDietTitle" and text()="Diet Category:"]/following-sibling::div[1]/span/text()
#1
0
I'm not sure I understood your question, but it sounds like you're looking for something like
我不确定我理解你的问题,但听起来你正在寻找类似的东西
//div[@class='viewSaveDietTitle'][. = 'Diet Category']/
following-sibling::div[1][@class='viewSaveDietData']/span/text()
This will select the text of the span that's a child of the div whose class is viewSaveDietData
, which immediately follows a div containing the title string 'Diet Category'. In other words, my understanding of your question is, how to select a particular span based on the title of the associated div
.
这将选择跨度的文本,该跨度是div的子节点,其类是viewSaveDietData,紧跟在包含标题字符串'Diet Category'的div之后。换句话说,我对您的问题的理解是,如何根据相关div的标题选择特定范围。
If you just want to select a span based on its order in the document, you could use
如果您只想根据文档中的顺序选择范围,则可以使用
(//span[@class = 'Answer'])[4]
#2
0
Some ways that I just tested (via the firefox selenium plugin and also the firefox xpath plugin) are:
我刚刚测试过的一些方法(通过firefox selenium插件以及firefox xpath插件)是:
//div[@class="viewSaveDietData"]/span[contains(text(), "Balanced")]
Also (more specificly):
(更具体地说):
//div[@class="viewSaveDietData"]/span[contains(@class, 'Answer') and text()="Balanced"]
Just by position with:
只需按位置:
//div[@class="viewSaveDietData"][4]/span
By Answer span alone (doesn't depend on being in the div) with
通过单独的答案范围(不依赖于在div中)
//span[contains(@class, 'Answer') and text() = "Balanced"]
(or more simply)
(或更简单地说)
//span[@class="Answer" and text()="Balanced"]
So:
所以:
//div[@class="viewSaveDietData"]/span[contains(@class, 'Answer') and text()="Balanced"]
is most specific which of course means it's most likely to be specific in selecting the desired elements but also will be more affected by page changes.
是最具体的,当然这意味着它最有可能在选择所需的元素时具体,但也会受到页面更改的影响。
#3
0
Got something similar to Larsh, but using /*/ instead of // as this makes search quicker. If titles are unique and if you are interested in answer for Diet Category the below code or one from LarsH should be good.
有类似于Larsh的东西,但使用/ * /而不是//因为这会使搜索更快。如果标题是唯一的,如果你有兴趣回答饮食类别,下面的代码或LarsH的代码应该是好的。
/*/div[@class="viewSaveDietTitle" and text()="Diet Category:"]/following-sibling::div[1]/span/text()