Element Location Using XPath Axis Part 2
In previous post, I have mentioned different ways of identifying web elements using XPath . Very often , we will have to identify child elements while automating using selenium. Let us consider below example . This is an HTML layout of table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Assuming we need to iterate across all the rows to identify which row have the name “Eve” and then do some action on that row . This can be achieved by below
1 2 3 4 5 6 7 8 9 10 11 |
|
Important step here is to use “.” in XPath so that selenium limit its search for current node rather than everywhere on document. This will help to identify elements with respective to another element.
Further details of how to use XPath can be found in https://www.w3schools.com/xml/xpath_syntax.asp
Main ones are
- / - Search from root
- // - Search anywhere in document which match selection
- . - select current node
- .. - select parent of current node