2

I'm new to Xpath and I wanted to know if there was a way to inspect a specific element, that is repeated multiple times throughout the webpage.

For this instance I want to inspect the specific span Allocation Exhausted (See picture below).

However, that element is repeated multiple times and I would like an Xpath, that focus's solely on any changes for this specific Allocation Exhausted.

Any help would be appreciated!

Image of the Inspected data

1

3 Answers 3

0

You can use this xpath in browser dev tools

//span[contains(text(),'Allocation Exhausted')]

Debugging xpath from browser dev tools

  1. Go to browser dev tools(Ctrl + shift + I)
  2. Click "Ctrl + F". You will have search field as shown in image below enter image description here
  3. Enter the required xpath
2
  • Thankyou, that is useful however there are multiple of the text 'Allocation Exhausted' (8 in total). I want to specify it down to this specific div/class/span. Is that at all possible? Jun 30, 2022 at 4:30
  • (//span[contains(text(),'Allocation Exhausted')])[1] will select 1st element from list so you should provide like (//span[contains(text(),'Allocation Exhausted')])[Specific Iteration]. Don't forget to Accept the answer Jun 30, 2022 at 4:55
0

Lets take an example of current page only and this is one of the approach that we follow in our automation testing services :

  • Here in this page with this given xpath - //li[@class=‘ps-relative’].
  • It is locating 5 elements and from here if you want to locate any one of the element, let say you want to locate “Companies” or fourth element then just pass the number where that element is located. (//li[@class=‘ps-relative’])[4]]
  • So by passing the exact position it will give you only that element on which you can perform action.
0

Finding the correct Xpath for multiple occurrences is a common scenario experienced in organizations that provide test automation services. In the above example, let's say we have 5 occurrences of the text- “Allocation Exhausted” We can write an Xpath as given below for the nth occurrence- (//span[contains(text(),'Allocation Exhausted')])[n]

So if we want to get the location of 3rd occurrence, we can use the XPath as given below: (//span[contains(text(),'Allocation Exhausted')])[3] Likewise, We can find the 1st,2nd,4th, and 5th occurrences per the requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.