Sunday, 18 February 2018

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. 
  1. ID
  2. Class Name
  3. Tag Name
  4. Class
  5. Using XPath
  6. Using  CSS
  7. Using Javascript
  8. 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.



0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home