kamal
kamal

Reputation: 9785

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.

Upvotes: 3

Views: 15946

Answers (2)

kamal
kamal

Reputation: 9785

This repo looks promising, as page object generation tool

look at Paul Grandjean Prototype Tool for Configurable Selenium Code Generation

https://github.com/pgrandje/pohelper2

Upvotes: 1

James
James

Reputation: 607

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.

Upvotes: 6

Related Questions