Question

How to find how many times a field occurs in a page

  • 2 August 2023
  • 3 replies
  • 125 views

Badge +2

Hi,

I am trying to find out how many times a particular field occurs in a page dynamically. The particular filed occurs 5 times once and 7 times some other time and so on. 

Exact Scenario: The Purchase order number field in the page is listed dynamically every time I load the page. Only if I know how many PO order fields are there, I can create a loop to run for the same number of times to fetch other details to populate. Hardcoding this wont work. Is there any package to check how many times a field occurs in page.

 

Regards,

Bala


3 replies

Userlevel 6
Badge +15

Hi @Balasamaran ,

You have to create the Loop to find the N number occurrence. 

Please use the loop and find actions to achieve this.

Note : Once you have find the value, increase the counter variable then loop will continue until the value doesn’t match. Also, each findings you have to increase the start from the location value. otherwise will be shown the same value again and again.

 

 

Badge +1

I did face similar issue and fixed by following below steps.

First identify the html node which is repeating. In my case, I’m looking for the image. 

//img (@src='images/health/critical.svg']

If there are 2 images on the page, you can iterate each image by using below in the domxpath.

(//img (@src='images/health/critical.svg'])[1]   -->Will pick first image

(//img (@src='images/health/critical.svg'])[2]   -->Will pick Second image.

 

I got the total count of images available by using the browser package run java script (below script) method and storing in integer variable.

document.evaluate (" / /img(@src='images/health/critical.svg']", document, null, |XPathResult. UNORDERED_ NODE_ SNAPSHOT_ TYPE, null). snapshotLength 

 

I have used the integer variable for the loop counter and (//img (@src='images/health/critical.svg'])[$loopCounter] as the domX path for the identified element, able to click on each image in a loop.

 

I hope this will help you. Let us know if you have further doubts.  

Badge +2

Thanks @sravan.aluvala and @Tamil Arasu10 . Your inputs helped. I was able to get the number of times an element appears in a page with a slight modification of your ideas. Thanks once again. 

Reply