I am using the following code to access a link (for phpunit/selenium):
//td[normalize-space() ='Test title 2']/following-sibling::td[3]/a[.='delete']
using an XPath checker in FireFox it returns 7 elements (because there are 7 links matching “test title 2”), but when I add [1] at the end:
//td[normalize-space() ='Test title 2']/following-sibling::td[3]/a[.='delete'][1]
it still returns 7 links. What am I doing wrong here?
When you add
[1]in the end of your expression, you select the firstachild of each...td[3](i.e. 7achild nodes). You can change your query to:or in case you use webdriver (xpath prefix is not needed):
This will select the first
afrom the entire set ofachildren of...td[3]elements.Refer to XPath Examples for more tutorials.