Is it possible to get ALL WebElements on a web page using WebDriver

Something like:

WebElement inputs = driver.findElement(By.tagName("input"));

or

List<WebElement> links = driver.findElementsBy(By.tagName("a"));

What i wanted was a name/value pair like structure which gives me tagName vs Quantity My Objective is to have a list of these Elements and make a Series of tests associated with them, since different users would have their own unique set of these Elements per page. I hope i got my message across.

3

2 Answers

You could do something like:

List<WebElement> allElements = driver.findElements(By.xpath("//*"));

or

List<WebElement> allElements = driver.findElements(By.cssSelector("*"));

Then just sort the list as needed using getTagName or other functions.

4

This repo looks promising, as page object generation tool

look at Paul Grandjean Prototype Tool for Configurable Selenium Code Generation

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like