Lets understand locators by asking WH questions.
Click on the image to enlarge it |
What are locators ?
When and Why they are required ?
Who are they ?
- Locators are the lifeblood of the tests.
- Locators are different strategies for locating elements on a page
- Locator can be termed as an address that identifies a web element uniquely within the webpage.
- Locators are the HTML properties of a web element.
When and Why they are required ?
- To tell the Selenium about the web element it need to perform action on
- To tell Selenium which GUI elements ( say Text Box, Buttons, Check Boxes etc) its needs to operate on.
- To get information of an element
Who are they ?
- Id
- Name
- Linktext
- Partial Linktext
- Tag Name
- Class name
- Css selectors
- selectors are patterns used to select the element(s) you want to style
- is the part of a CSS rule set that actually selects the content you want to style
- XPath expression
- document is parsed into a tree structure (DOM tree)
- for selecting nodes from a document
- is used to navigate through elements and attributes in a document.
- abstract class By inside the package org.openqa.selenium
- subclasses of By and interfaces
- Using developer tools available in browsers
- Right-click --> Inspect Element or Inspect (Firefox / Crome)
- Using browser add-on like this
- Example:
- <input name="register" class="required" type="text"/>
- WebElement register= driver.findElement(By.name("register"));
- There is no perfect locator
- If you’re smart about your locators you can reduce the cost of maintenance
- http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html
- http://www.seleniumeasy.com/selenium-tutorials/selenium-locators
- http://toolsqa.com/selenium-webdriver/locators/
- http://www.guru99.com/locators-in-selenium-ide.html
No comments:
Post a Comment