问题
I want to create xpath which must contain word "Asia"
//div[@id='destination-loadLevel0']/div/ul/li/div/div/span
*for Asia
//div[@id='destination-loadLevel0']/div/ul/li[2]/div/div/span
*for Europe
//div[@id='destination-loadLevel0']/div/ul/li[3]/div/div/span
*for USA
//<div class="col-md-3 level-column column-viewport" id="destination-loadLevel0">
<div class="row">
<ul>
<li class="col-md-3 col-hotspot unselectable-text" data-parent-group-id="" data-groupid="2244604" data-name="Asia;|03|00|00|">
<div class="tile-container">
<div class="image-label" data-toggle="tooltip" data-container="body" data-placement="top" title="" data-original-title="Asia">
<span class="title ellipsis">Asia</span>
<span class="icon icon-angle-right"></span>
</div>
回答1:
//*[contains(text(),'Asia')] | //@*[contains(.,'Asia')]/parent::*
returns all elements whose text contains 'Asia' or whose attribute values contains 'Asia'
Output :
<li class="col-md-3 col-hotspot unselectable-text" data-parent-group-id="" data-groupid="2244604" data-name="Asia;|03|00|00|" />
<div class="image-label" data-toggle="tooltip" data-container="body" data-placement="top" title="" data-original-title="Asia" />
<span class="title ellipsis">Asia</span>
来源:https://stackoverflow.com/questions/37482315/create-xpath-manually