Friday, 27 March 2015

Find all the Links on a Webpage

It is quite easy to find all the links from a page and it is quite useful in Automation testing. As there will be situations when you want to count all the links from a webpage or to check that none of the links on the webpage are throwing ‘Page not Found‘ errors or there can be a situation when you drive your test through the links present on the web page.
Step to follow…
1) Navigate to the interested webpage for e.g. www.toolsqa.com.
2) Create a list of type WebElement to store all the Link elements in to it.
3) Collect all the links from the webpage. All the links are associated with the Tag ‘a‘.
4) Now iterate through every link and print the Link Text on the console screen.
Output will be like this:
The same way you can easily be able to find any type of WebElements on a WebPage:
Find total number of Checkboxes on a Webpage :

Find total number of Menus on a Webpage :

Find total number of TextBoxes on a Webpage :

No comments:

Post a Comment