How do I repeat on page elements?
Question ID: 359
1
0

Im trying to find a way to find and follow links on a page.   How can I get a list of links on a page?

Marked as spam
Posted by (Questions: 5, Answers: 4)
Asked on June 19, 2023 6:19 pm
9 views

Answers (1)

1
Private answer

The same Repeat action used for repeating over a fixed count or data rows can be used to loop of elements.  First, you need to define a locator that can return multiple elements.  When recording or capturing elements, we do not capture anything that returns more than one result.  To define a locator that returns multiple elements, you will need to select the Inspector view on the browser window.

From there, you can define and test your locator using the Search panel at the top right.  If your locator returns multiple elements, which is the goal here, then it will no longer show element details, but instead a list of elements that were found.  Once your locator has been testing, click Add This Element at the bottom then the locator is ready.

Now, we need to define our Repeat action to use the new locator.  In the Repeat action, set the loopMode to Page Elements.  Select your new locator for targetLocator and the function you wish to execute for each iteration.  Lastly, it is recommended to set an Output name.  For this example, I will use the Output name 'anchors'.

Each iteration of your function now has a reference to the current page element in the loop via a context variable named element.  Since we defined an Output name of anchors, we can reference the context variable as anchors_element.  If you pass that context variable to any action that uses a locator, it will use the located element instead of looking up a new one.

Let me know if that makes sense

cm

Marked as spam
Posted by (Questions: 0, Answers: 38)
Answered on June 26, 2023 8:02 am

Welcome to Alchemy Center!
Please Log In to participate in the discussion.

X
Scroll to Top