InterviewSolution
| 1. |
What does Locator mean? Name different types of locators. |
|
Answer» Id Locator : The ID locator SEARCHES for an element having an id attribute corresponding to the specified pattern on the page. Syntax is - driver.findElement(By.id("id value")); PROS:
CONS:
Name Locator : The Name locator searches for an element having a name attribute corresponding to the specified pattern on the page. You can specify a filter to refine your locator. Syntax is - driver.findElement(By.name("name-value")); PROS:
CONS:
Link Locator: The link locator is intended to select links only and selects the anchor element containing the specified text: link=The text of the link Syntax is - driver.findElement(By.linkText("link text")); PROS:
CONS:
DOM Locator : The DOM locator works by locating elements that match the javascript expression referring to an element in the DOM. Locating by getElementById Syntax is - document.getElementById("id of the element"); Locating by getElementsByName Syntax is - document.getElementsByName("name")[index]; Locating by DOM - dom: name Syntax is - document.forms["name of the form"].elements["name of the element"]
Locating by DOM - dom: index Syntax is - document.forms[index of the form].elements[index of the element]
PROS:
CONS:
XPath Locator: XPath is the navigation tool for XML. XPath can be USED everywhere where there is XML. Xpath Locate element by using an XPath expression. Syntax is - //button[@value="value text"]; //div[@id="id value"]/button[0];PROS:
CONS:
CSS Locator To find the elements on the page, the CSS locator uses CSS selectors. Syntax is - div[id="id value"] > button[value="value text"]; selects the button with its value property set at value text if children of the id value are div PROS:
CONS:
Structure-Dependent Or Not? Locators are classified into two categories ie Structure-based locators and Attributes-based locators.
|
|