XPath: Using following
XPath Following:
The following XPath axis is used to locate elements that come after the current node in the document tree. In the examples below, the first one selects the first input element that follows the "organization" element. The second example selects all input elements that follow the "organization" element. This axis is particularly useful when locating elements in a table or when you have no specific information about the elements that follow the current node.
This selects the first input element following the element with the name "organization_name".
Example 1: XPath= //input[@name='organization_name']//following::input[1]
This selects all input elements following the element with the name "organization_name".
Example 2: XPath= //input[@name='organization_name']//following::input
XPath following sibling:
With the following axis, all nodes that appear after the current node in the document tree are selected, regardless of whether they are children of the current node. However, with the following-sibling axis, only nodes that share the same parent as the current node (i.e., the siblings that come after it) are selected. In this context, "siblings" refers to nodes that are all children of the same parent node.
Therefore, if you reference one child node and want to navigate to its siblings that come after it, the following-sibling axis is the right tool to use.
This selects all li elements that are siblings of the element with the class "sign-in" and that follow it.
Example 1: XPath= //li[@class='sign-in']//following-sibling::li