Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - Find all elements of a web page

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?

like image 985
AryA Avatar asked Oct 30 '13 13:10

AryA


2 Answers

Yes, there is a way.

Here is some pseudo-code:

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

for ( WebElement e : el ) {
  add(e.tagName());
}
like image 121
ddavison Avatar answered Nov 19 '22 02:11

ddavison


non-pseudo C# version of above: (although I'm just displaying the results in a console

IReadOnlyCollection<IWebElement> el = driver.FindElements(By.CssSelector("*"));
foreach (IWebElement elm in el)
{
    Console.WriteLine(elm.TagName + elm.Text);
}
like image 1
chetstriker Avatar answered Nov 19 '22 03:11

chetstriker