Issue
Problem: I need to cycle through all the elements on a webpage, using C# and Selenium. The goal is to discover the attributes for an existing web page without knowing the Ids or other attributes. Put another way, how do you perform FindElements to return a list of all the IWebElements on a page, not just a specific type or id mask?
So far: I found a javascript command to print out all the attributes of a given element, which can be called from C# on each element as its found. The javascript command does not need to know the type of the element.
Need to Solve: How does one use Selenium to retrieve a list of all the IWebElements on a web page?
Overall Goal: In the past, I've used other tools to create a wrapper object for all the elements of the webpage I would potentially need to interact with while writing test automation. (For those who've used WatiN, this is an adapter written automatically using the collection of all web controls on the page.)
Solution
If you really just want a giant list of every element, you can just use XPath like this (unless I'm missing something more in your question) --
Given a 'Browser' object:
var elements = Browser.FindElements(By.XPath("//*"));
Answered By - Marc Plowey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.