This post is fourth in a series of six. Need to go back to the beginning?
Part Four: Storing locators in Enums
How to locate a web element?
There are two main they locate web elements at work:
- By ID
- By CSS Selector
With the Firefox browser and the Firebug plugin, to find the selectors of a web element, an automated tester can go to the Login Page of Dave Haeffner's test site, The-Internet, and right-click on each element listed:
Welcome to The-Internet. |
There are three main web elements on the page: the Username textbox, the Password textbox, and the Login button.
If you have Firefox with the Firebug plugin and Firepath installed, you can go to each element, right-click on the element, and select "Inspect in Firepath":
Username textbox:
- <input id="username" type="text" name="username"/>
Password textbox:
- <input id="password" type="password" name="password"/>
Login button:
- <button class="radius" type="submit">
We see that an automated tester can choose to select the web elements by either Id or by CSS Selector. For this example, just to illustrate how they are used, I will use CSS selectors. They are:
- The Username textbox: [name='username']
- The Password textbox: [name='password']
- The Login button: [class='radius'][type='submit']
WebElement txtUsername = driver.findElement(By.id("username"));
System.out.println("Entering username...");
txtUsername.sendKeys(username);
1 comment:
Storing locators for web elements involves saving identifiers such as XPath, CSS selectors, or IDs used to locate specific elements on a web page within automated testing frameworks or tools. These locators are crucial for referencing and interacting with elements programmatically, facilitating robust and efficient test automation processes. Efficient management and utilization of locators enhance the reliability and maintainability of automated tests.
virginia uncontested divorce
uncontested divorce in va
Post a Comment