Selenium Locators

Selenium Locators – How to Identify Web Elements in Selenium?

Selenium, Selenium Training In Bangalore, Selenium Course Training In Bangalore, Selenium Course Training in Mathikere, Malleshwaram, Rajajinagar, Jayanagar, Bangalore, Selenium Training In Near Me

Locators – It is a strategy to identify the Web Elements on the application under test. In WebDriver this is possible through two methods exposed by every language bindings called as “findElement” and “findElements”. These methods use the “By” Locator/Object to identify each and every WebElement, following are the different locator strategies

Following DOM tag is used for illustrating examples

<input type=”text” name=”session_key” class=”login-email-reg-field__input” autocapitalize=”off” tabindex=”1″ id=”login-email” placeholder=”Email or phone number” autofocus=”autofocus”>
EX-  driver.findelement(“login-email”));
ClassName – An attribute of the DOM element
Ex –  driver.findelement(By.classname(“login-email-reg-field__input”));
Tag Name – use the tag name of the DOM element
Ex – driver.findelement(By.tagName(“input”));
Ex – driver.findelement(“session_key”));
Ex – driver.findelement(By.linkText(“Forgot Password”));
PartialLink Text
Ex – driver.findelement(By.partialLinkText(“Forgot”));
Ex –  driver.findelement(By.cssSelector(“#reg-lastname”));
Ex – driver.findelement(By.xpath(“//input[@id=”reg-lastname”]));