User description
In this commit i have added the code inside LocatorsTest, for various types of locators (className, id, xpath), and reffered that code in the corresponding documentation files.
This PR intends in helping to "move code" for elements -> locators -> java bindings.
Right now i haven't added the code examples for relative locators, because i felt there are different websites to show the practical code examples for the same.
Although that code is also ready, if you feel its fine, then in the next commit i can include the following code, and make appropriate changes in the documentation files. But in this case, i guess we will have to change the static image (that is currently attached), or give a better context, that how we are using multiple websites to show the relative locators strategies.
public void findElementByAboveRelativeLocator() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");
// Find element by above relative locator
By emailLocator = RelativeLocator.with(By.tagName("input")).above(By.id("password"));
WebElement element = driver.findElement(emailLocator);
}
public void findElementByBelowRelativeLocator() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");
// Find element by below relative locator
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("user-name"));
WebElement element = driver.findElement(passwordLocator);
}
public void findElementByLeftOfRelativeLocator() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev/selenium/web/login.html");
// Find element by left of relative locator
By emailLocator = RelativeLocator.with(By.tagName("input")).toLeftOf(By.id("password-field"));
WebElement element = driver.findElement(emailLocator);
}
public void findElementByRightOfRelativeLocator() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev/selenium/web/login.html");
// Find element by right of relative locator
By passwordLocator = RelativeLocator.with(By.tagName("input")).toRightOf(By.id("username-field"));
WebElement element = driver.findElement(passwordLocator);
}
public void findElementByNearRelativeLocator() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev/selenium/web/login.html");
// Find element by near relative locator
By loginButtonLocator = RelativeLocator.with(By.id("login-form-submit")).near(By.id("password-field"));
WebElement element = driver.findElement(loginButtonLocator);
}
public void findElementByChainingRelativeLocators() {
WebDriver driver = new ChromeDriver();
driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html");
// Find element by chaining relative locators
By newsLetterCheckboxLocator = RelativeLocator.with(By.name("newsletter"))
.toRightOf(By.xpath("//label[@for='newsletter']")).below(By.id("lname"));
WebElement element = driver.findElement(newsLetterCheckboxLocator);
}
Also i haven't added any assertions, since they were not present before, although if you want i can add assertion and convert each method as a test case too.
I wasn't able to verify the changes by running hugo server cause the required code only doesn't exist, and its being added right now.
Please let me know if any changes are needed.
Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Motivation and Context
Types of changes
Checklist
PR Type
Documentation, Enhancement
Description
-
Added Java methods for various locator strategies (className, id, cssSelector, etc.) in LocatorsTest.
-
Introduced relative locators and their usage in Java, with examples for above, below, toLeftOf, and toRightOf.
-
Updated formatting, alignment, and examples in locators documentation across multiple languages (Portuguese, Chinese, Japanese, and English).
-
Replaced inline code examples in documentation with references to external Java code files.
-
Improved descriptions, explanations, and clarity for locator strategies in the documentation.
Changes walkthrough 📝
| Relevant files |
|---|
| Documentation |
locators.pt-br.mdImproved formatting and examples in Portuguese locators documentation.
website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md
Updated formatting and alignment of locator strategy tables. Enhanced HTML examples for better readability and consistency. Replaced inline code examples with references to external code files. Improved descriptions and explanations for locator strategies.
+275/-271
locators.zh-cn.mdImproved formatting and examples in Chinese locators documentation.
website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md
Updated formatting and alignment of locator strategy tables. Enhanced HTML examples for better readability and consistency. Replaced inline code examples with references to external code files. Improved descriptions and explanations for locator strategies.
+274/-271
locators.ja.mdImproved formatting and examples in Japanese locators documentation.
website_and_docs/content/documentation/webdriver/elements/locators.ja.md
Updated formatting and alignment of locator strategy tables. Enhanced HTML examples for better readability and consistency. Replaced inline code examples with references to external code files. Improved descriptions and explanations for locator strategies.
+276/-270
locators.en.mdImproved formatting and added Java code references in locators
documentation.
website_and_docs/content/documentation/webdriver/elements/locators.en.md
Adjusted formatting and indentation for consistency in the documentation. Updated examples to reference Java code snippets from the LocatorsTest file. Improved descriptions and explanations for locator strategies and relative locators. Enhanced clarity by rephrasing and restructuring some sections.
+273/-268
|
| Enhancement |
LocatorsTest.javaAdded Java examples for locator strategies in Selenium tests.
examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java
Added Java methods for various locator strategies (className, id, cssSelector, etc.). Included examples for using By locators and chaining locators. Improved structure and organization of test methods for clarity. Introduced relative locators and their usage in Java.
+94/-5
|
Need help?
Type /help how to ... in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.
Uh oh!
There was an error while loading. Please reload this page.
User description
In this commit i have added the code inside LocatorsTest, for various types of locators (className, id, xpath), and reffered that code in the corresponding documentation files.
This PR intends in helping to "move code" for elements -> locators -> java bindings.
Right now i haven't added the code examples for relative locators, because i felt there are different websites to show the practical code examples for the same.
Although that code is also ready, if you feel its fine, then in the next commit i can include the following code, and make appropriate changes in the documentation files. But in this case, i guess we will have to change the static image (that is currently attached), or give a better context, that how we are using multiple websites to show the relative locators strategies.
Also i haven't added any assertions, since they were not present before, although if you want i can add assertion and convert each method as a test case too.
I wasn't able to verify the changes by running hugo server cause the required code only doesn't exist, and its being added right now.
Please let me know if any changes are needed.
Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Motivation and Context
Types of changes
Checklist
PR Type
Documentation, Enhancement
Description
Added Java methods for various locator strategies (className, id, cssSelector, etc.) in
LocatorsTest.Introduced relative locators and their usage in Java, with examples for
above,below,toLeftOf, andtoRightOf.Updated formatting, alignment, and examples in locators documentation across multiple languages (Portuguese, Chinese, Japanese, and English).
Replaced inline code examples in documentation with references to external Java code files.
Improved descriptions, explanations, and clarity for locator strategies in the documentation.
Changes walkthrough 📝
locators.pt-br.md
Improved formatting and examples in Portuguese locators documentation.website_and_docs/content/documentation/webdriver/elements/locators.pt-br.md
locators.zh-cn.md
Improved formatting and examples in Chinese locators documentation.website_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md
locators.ja.md
Improved formatting and examples in Japanese locators documentation.website_and_docs/content/documentation/webdriver/elements/locators.ja.md
locators.en.md
Improved formatting and added Java code references in locatorsdocumentation.website_and_docs/content/documentation/webdriver/elements/locators.en.md
documentation.
LocatorsTestfile.
relative locators.
LocatorsTest.java
Added Java examples for locator strategies in Selenium tests.examples/java/src/test/java/dev/selenium/elements/LocatorsTest.java
cssSelector, etc.).
Bylocators and chaining locators.