How many ways to select an element in Selenium?
There are so many elements are available on a web page and to identify and locate an element on that page you need to mention the location of that particular element.
- ID
- Class Name
- Tag Name
- Class
- Using XPath
- Using CSS
- Using Javascript
- AutoIT(Alternative way)
Id:- Specify element by their id name in DOM
example:- driver,findElementById("Example") ;
Class Name:- Specify element by their class name in DOM
example:- driver.findElementByClassName("Example");
Tag Name:- Specify element by their tag name
example:- driver.findElementByTagName("Example");
XPath:-
XPath uses 'path like' syntax to identify and navigate nodes in an XML document.
example: - //a[@id="example"]
CSS:-
CSS is the simplest form of an element location. It has much more benefits compared to XPath. The major one is the fastest UI interaction. When working on IE, most of the times XPath won't work.
example:- #example
Javascript:-
The fastest way to interact UI elements, implement with java executor. Due to JS asynchronous behavior, it is hard to manage.
example:- document.getElementById("example");
AutoIT:-
Used it when no methodology works. It is the simplest form of implementation to interact with UI.
Rather than DOm reading, it finds element image on a screen. Highly unstable, a slight modification can break consistency.
example:- driver,findElementById("Example") ;
Class Name:- Specify element by their class name in DOM
example:- driver.findElementByClassName("Example");
Tag Name:- Specify element by their tag name
example:- driver.findElementByTagName("Example");
XPath:-
XPath uses 'path like' syntax to identify and navigate nodes in an XML document.
example: - //a[@id="example"]
CSS:-
CSS is the simplest form of an element location. It has much more benefits compared to XPath. The major one is the fastest UI interaction. When working on IE, most of the times XPath won't work.
example:- #example
Javascript:-
The fastest way to interact UI elements, implement with java executor. Due to JS asynchronous behavior, it is hard to manage.
example:- document.getElementById("example");
AutoIT:-
Used it when no methodology works. It is the simplest form of implementation to interact with UI.
Rather than DOm reading, it finds element image on a screen. Highly unstable, a slight modification can break consistency.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home