Selenium - Find all elements of a web page

AryA picture AryA · Oct 30, 2013 · Viewed 41.5k times · Source

I am planning a tool in Java which would have a drop down containing all the elements of a web page. Is there any way I can read those into a data structure?

Answer

ddavison picture ddavison · Oct 30, 2013

Yes, there is a way.

Here is some pseudo-code:

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

for ( WebElement e : el ) {
  add(e.tagName());
}