How to get all links of a web page using OATS

Like Tweet Pin it Share Share Email

It is a very common requirement in automated testing to get the list of all links, the instance when this is generally required is:

  1. To see if all desired links are present in a web page.
  2. In case of multiple links having same text, there would be necessity to click on a specific link though the link texts are same.

Oracle Application Testing Suite also provides ways to get the list of all links or buttons or any UI components in a web page, before we deep diving in to details, we have to understand something called DOM – Document Object Model.

Lets now look at 3 different options of getting list of all links or buttons or UI Components from a web page:

  • Using getElementByTagName with just the name.
  • Using getElmenetByTagName with name and with selection criteria.
  • Using javascript

Using getElementByTagName with just the name

For example for link it would be “a”, for button it could be “button” / “input” with type as button or submit, for image it would be “img”, we need to supply this as an input. We should be able to get all links from the web page document with following line of code.

Make sure appropriate packages are loaded to have DOMElement and List, in eclipse you can press a short cut Ctrl + Shift + o it will include the dependent packages automatically.

Now we can iterate through the complete list and reach to your desired link and perform any action.

As we see this is one way to iterate through all the links and access them.

Using getElmenetByTagName with name and with selection criteria

this is  an another tricky way to directly get all links which are with a specific name like “Home”, as if we need to loop through all links and find out the link it can have performance hit on the automation script.

look at the function implemented it can be used by any one their projects 🙂

Below method assumes that there is only one link in the web page with a specific name, in case there are multiple method needs an enhancement accordingly.

There is also an another way to acheive this by executing javascript code from Openscript, will come up with a new article to do with javascript as well, this is one of the fastest way to perform the action but needs good programming knowledge too.

hope this gives you an understanding how to get list of objects and the internal mechanism for the same. please do ask your queries in form of comments I would be more than happy to help.

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *