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”>
ID
EX-  driver.findelement(By.id(“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”));
Name
Ex – driver.findelement(By.name(“session_key”));
LinkText
Ex – driver.findelement(By.linkText(“Forgot Password”));
PartialLink Text
Ex – driver.findelement(By.partialLinkText(“Forgot”));
CSS
Ex –  driver.findelement(By.cssSelector(“#reg-lastname”));
XPath
Ex – driver.findelement(By.xpath(“//input[@id=”reg-lastname”]));

Latest Blogs

Free Demo

Contact

Contact Phone
+91 98458 34306
Office Address
347, HMT Main Road, Mathikere, Bangalore
Office hours
Mon - Sun: 9:00am - 8:00pm
Social media & sharing icons powered by UltimatelySocial
Facebook
Twitter
LinkedIn
Instagram
Book Your Demo

Up-Skill your career with one of the leading Selenium and Digital Marketing training company in Bangalore, India