Best way to iterate over a webpage buttons that are dinamicaly generated
Hi all, i’m trying to automate extraction of information from a website. The page that lists the content has a button for each line, that needs to be clicked to get more information. This buttons are generated at run time acording to the content of the page and I honestly can find any difference in their html definition. What would be the best technique to interate the buttons on this page ? Each page contains 10 of these buttons and then “next” must be clicked.
I’m not aware if it would be possible to repeat all the capture actions that are done to get the information, like a function that could be called once we reach a certain html page. If this could be done, I could record the clicking on each one of those 10 buttons and call the function that extracts information. Otherwise I would have to repeat everything …
thank you,
Pedro
Page 1 / 1
Hey there,
There's a straightforward way to tackle this.
You'll need a while loop to continually check if the "next" button is available. Within this loop, continuously verify if the "next" button is clickable or available, which can be determined through capture.
Within this loop, you'll need another loop. Since each page contains multiple items that need iteration, you can create a loop that dynamically adjusts based on the number of items present. This way, your counter adapts to the number of elements on each page, ensuring comprehensive coverage.
Within this inner loop, select the correct element using the capture method. There are various ways to achieve this, such as using XPath to select the right button on the website. Ensure that the counter dynamically adjusts to select the appropriate button, ready to be clicked.
With this setup, you'll have your business logic in place, adaptable to variations in the number of elements on each page.
Thank you. I understand the logic of course, my only problem is how to programaticaly select the different buttons on the row because all seem to have the same name. I will try to see if their XPATH is different, maybe thats the option.
@pcasqueiro, Can you please share the xPath of multiple buttons, so that we can identify which section is changes and then pass a counter variable to make it dynamic.
Hi Zaid,
thank you for your help. I really don’t understand how can I place a capture inside a loop, changing the path dinamically.
A little context so that you can point me in the right direction. Each row (with a maximum of 10 por page) has a small Action Menu implemented with a DIV, that we need to click in order to access the Ver Detalhes (see details) option.
On the button of this page, there is a link for the next page “Seguinte”. On the last page, this link is greyed out.
So I guess the outer loop must be until we find this string Grayed Out and its now a LABEL, not an anchor anymore.
After clicking the small action menu, we have to choose the correct action we want, in this case Ver Detalhes (see details):
I have capture the properties of the menu (button) and option (Anchor) of the first 4 rows:
ROW 1
Click Small Menu HTML Tag: BUTTON DOMXPath: //button/@id='dropdownMenuButton'] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|1|-1|1|1 HTML Tag: A
Click inside Small Menu in Ver Detalhes DOMXPath: //divh@id='single-spa-application:@agt/ip']/app-root-ip-1]/divp2]/app-lista-consultac1]/diva1]/divv1]/divv1]/app-lista-predios-1]/divs1]/divv2]/divv1]/divv1]/divv2]/divv1]/span[5]/divn1]/divv1]/ad3] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|1|-1|1|-1|-1
ROW 2
Click Small Menu HTML Tag: BUTTON DOMXPath: //button/@id='dropdownMenuButton'] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|2|-1|1|1 HTML Tag: A
Click inside Small Menu in Ver Detalhes DOMXPath: //divh@id='single-spa-application:@agt/ip']/app-root-ip-1]/divp2]/app-lista-consultac1]/diva1]/divv1]/divv1]/app-lista-predios-1]/divs1]/divv2]/divv1]/divv1]/divv2]/divv2]/span[5]/divn1]/divv1]/ad2] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|2|-1|1|-1|-1
ROW 3
Click Small Menu HTML Tag: BUTTON DOMXPath: //button/@id='dropdownMenuButton'] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|3|-1|1|1 HTML Tag: A
Click inside Small Menu in Ver Detalhes DOMXPath: //divh@id='single-spa-application:@agt/ip']/app-root-ip-1]/divp2]/app-lista-consultac1]/diva1]/divv1]/divv1]/app-lista-predios-1]/divs1]/divv2]/divv1]/divv1]/divv2]/divv3]/span[5]/divn1]/divv1]/ad3] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|3|-1|1|-1|-1
ROW 4
Click Small Menu HTML Tag: BUTTON DOMXPath: //button/@id='dropdownMenuButton'] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|4|-1|1|1 HTML Tag: A
Click inside Small Menu in Ver Detalhes DOMXPath: //divh@id='single-spa-application:@agt/ip']/app-root-ip-1]/divp2]/app-lista-consultac1]/diva1]/divv1]/divv1]/app-lista-predios-1]/divs1]/divv2]/divv1]/divv1]/divv2]/divv4]/span[5]/divn1]/divv1]/ad3] Path: 2|1|1|2|-1|1|1|1|-1|1|-1|1|1|-1|4|-1|1|-1|-1
My main doubt is how to use a single Recorder: Capture to click both the Button and the Anchor …
thanks a lot,
Pedro
go to while loop then check if object exist, here you can select next button...this may be your outer loop and then in inner loop you can check for further automation . If you are using xpath do try using counter in place where you see fields changing and increment it.
Just to confirm, if I just change the PATH propertie (I assume using a var inside the string) the action will be done on the page object with that path ? all other properties will be ignored ?
So, I placed inside a Loop, a Recorder: Capture where I changed the PATH propertie to: