Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore first and last element in xpath

Tags:

xpath

How to ignore first and last element in xpath? Couldnt find any example on the internet. I only found that you can use [position()>1] to ignore first element but how i can ignore last too?

like image 703
biox Avatar asked Aug 01 '13 19:08

biox


People also ask

How do I ignore the first element in XPath?

However, if you wanted to address all of the a elements you need to modify the XPATH slightly. In the context of the expression //a[position()>1] each one of the a elements will have a position() of 1 and last() will evaluate to true. So, it would always return every a and would not skip over the first one.

How to get last element in XPath?

Let us consider an example in which we will try to locate the last text field on the Google sign-up page i.e. "Confirm Password" field. Using XPath- last() method, we can write the Java code along with the dynamic XPath location as: findElement(By. xpath("(//input[@type='text'])[last()]"))

What is text () in XPath?

XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.


1 Answers

Try [position()>1 and position()<last()]

like image 111
paul trmbrth Avatar answered Sep 28 '22 03:09

paul trmbrth