This is the code that I currently have:
I have tried the following:
I am using selenium, and I want it to click on the edit button that is right after the ABZ
span
.user3525228user3525228
Selenium WebDriver provides a user-facing API for performing complex user gestures. Performs click-and-hold at the location of the source element, moves on the x-axis by a given xOffset and on the y-axis by the given yOffset, then releases the mouse. Using Actions Class perform the following keyboard and mouse actions, Locate and click.
2 Answers
This xpath worked for me in Chrome, using your html:
Edit
The
..
means to go up a level. The ..
takes the selector from span
to section
. Then the following-sibling
finds the section
after the parent section
of your matching span
.Your original selector was matching
span
, then looking for a following-sibling
to span
.RichardRichard
Adding to the answer above, both the expressions below will work well.
OR
![Selenium following axis formula Selenium following axis formula](/uploads/1/2/3/7/123727172/234160894.jpg)
Notably, the axis following will pick each node following the context node while the axis following-sibling will only pick the sibling nodes to the context node.
Mohit AroraMohit Arora
Not the answer you're looking for? Browse other questions tagged seleniumxpath or ask your own question.
As we know that path defines the location of a node using absolute or relative path. In the same manner XPath axes are used to identify elements by their relationship like parent, child, sibling, etc. Axes refer to axis on which elements are lying relative to an element.
A list of various Axis values:
Index | Axis | Description |
---|---|---|
1) | ancestor | It specifies the ancestors of the current nodes which include the parents up to the root node. |
2) | ancestor-or-self | It specifies the current node and its ancestors. |
3) | attribute | It specifies the attributes of the current node. |
4) | child | It specifies the children of the current node. |
5) | descendant | It specifies the descendants of the current node i.e. the node's children up to the leaf node(no more children). |
6) | descendant-or-self | It specifies the current node and it's descendants. |
7) | following | It specifies all nodes that come after the current node. |
8) | following-sibling | It specifies the following siblings of the context node. Siblings are at the same level as the current node and share it's parent. |
9) | namespace | It specifies the namespace of the current node. |
10) | parent | It specifies the parent of the current node. |
11) | preceding | It specifies all nodes that come before the current node (i.e. before it's opening tag). |
12) | self | It specifies the current node. |
XPath Axes Example
Here the firstname is related to employee node of the XML document named employee.xml
Let's create an XML document named 'employee.xml' and its stylesheet document named 'employee.xsl' which uses the XPath expression.
Employee.xml
![Axis Axis](/uploads/1/2/3/7/123727172/385641804.gif)
Employee.xsl
Output: