简体   繁体   中英

Why is the following-sibling expression incorrect?

For this general structure:

<div class="col-xs-10">
    <input id="This[0].That" name="This[0].That" ng-model="item.That">
</div>
<div class="col-xs-2">
    <input ng-click="removeThat(item)" value="Remove">
</div>

why is this particular syntax invalid:

//input[@id='This[0].That']/following-sibling::/../input[@value="Remove"]

?

To answer your direct question, you're getting an XPath syntax error because following-sibling:: must be followed by an NCName such as input :

`following-sibling::input`

However, note that the input elements in your sample HTML are not siblings.

You could choose the second input based upon the first by using the following:: axis instead:

//input[@id='This[0].That']/following::input[@value="Remove"]

Of course, for just the small sample, a simpler XPath would suffice:

//input[@value="Remove"]

Just adding to what kjhuges said, if your reasoning behind using the first input to anchor off of was because there were multiple //input[@value='Remove'] elements, you can always use an index to find them or modifier tags

(//input[@value='Remove'])[index] 

//input[@value='Remove'])[last()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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