How many ways to select an element in Selenium?
- ID
- Class Name
- Tag Name
- Class
- Using XPath
- Using CSS
- Using Javascript
- AutoIT(Alternative way)
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.