Locators (XPath, CSS, ID, Name)
Quality Thought is recognized as the best software testing institute in Hyderabad, offering top-notch training in manual testing, automation testing, and full stack testing tools. With a focus on industry-relevant curriculum and hands-on practice, Quality Thought prepares students for real-world software testing challenges. The institute provides expert-led training on popular tools and frameworks like Selenium, TestNG, Jenkins, Git, Postman, JIRA, Maven, and Cucumber, covering both frontend and backend testing essentials.
Quality Thought’s Full Stack Testing course is specially designed to make students proficient in both manual testing fundamentals and automated testing tools, along with exposure to API testing, performance testing, and DevOps integration. The institute stands out for its experienced trainers, live projects, placement support, and flexible learning options including classroom and online modes.
Whether you are a fresher aiming for a job or a working professional looking to upskill, Quality Thought offers customized learning paths. Its strong industry connections ensure regular placement drives and job interview
Locators (XPath, CSS, ID, Name)
In Selenium, locators are used to identify elements on a web page. The most common locators are ID, Name, XPath, and CSS Selector.
1. ID Locator
The id attribute is unique for each element. It is the fastest and most reliable locator.
Example: driver.findElement(By.id("username"));
2. Name Locator
This uses the name attribute. It is helpful when ID is not available.
Example: driver.findElement(By.name("email"));
Note: If multiple elements have the same name, it may select the first one.
3. XPath Locator
XPath is a powerful way to find elements using paths. It can navigate through any part of the HTML DOM.
There are two types:
-
Absolute XPath:
/html/body/div/input -
Relative XPath:
//input[@type='text']
Example:driver.findElement(By.xpath("//button[text()='Submit']"));
4. CSS Selector
CSS selectors are fast and clean. They allow finding elements by ID, class, attribute, etc.
Examples:
-
By ID:
#login -
By class:
.btn -
By attribute:
input[type='text']
Code:driver.findElement(By.cssSelector("input[type='text']"));
Summary:
-
Use ID when available.
-
Use Name when ID is missing.
-
Use XPath for complex elements.
-
Use CSS Selector for speed and flexibility.
Locators are key to writing stable and accurate Selenium tests.
Learn More
Comments
Post a Comment