You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
added locator code file for java for locator strategies Section and added content in diff languages files
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
Added java program for locators and added the code block in diff files
Motivation and Context
it wasn't there.
Types of changes
Change to the site (I have double-checked the Netlify deployment, and my changes look good)
Code example added (and I also added the example to all translated languages)
Improved translation
Added new translation (and I also added a notice to each document missing translation)
The PR removes LocatorsTest.java, which has examples for ByAll and ByChained locators. These examples should be added to the new LocatorTest.java and linked in the documentation to prevent content loss.
Why: The suggestion correctly identifies that the PR removes valuable examples for ByAll and ByChained locators without replacing them, which is a significant content regression for a PR focused on improving examples.
Medium
General
Improve test robustness for tag name
In testTagName, use findElements to get all tags and assert that at least one has the correct href, making the test more robust against DOM changes.
@Test
public void testTagName() {
- WebElement element = driver.findElement(By.tagName("a"));- Assertions.assertNotNull(element);- Assertions.assertEquals("https://www.selenium.dev/", element.getAttribute("href"));+ java.util.List<WebElement> elements = driver.findElements(By.tagName("a"));+ Assertions.assertTrue(elements.stream()+ .anyMatch(e -> "https://www.selenium.dev/".equals(e.getAttribute("href"))));
}
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: This is a good suggestion that improves the robustness of the testTagName test by using findElements and checking for any match, which prevents the test from breaking if the element order changes.
Low
Improve test robustness for class name
In testClassName, use findElements to retrieve all elements with the class "information" and verify at least one is an tag to improve test reliability.
@Test
public void testClassName() {
- WebElement element = driver.findElement(By.className("information"));- Assertions.assertNotNull(element);- Assertions.assertEquals("input", element.getTagName());+ java.util.List<WebElement> elements = driver.findElements(By.className("information"));+ Assertions.assertTrue(elements.stream()+ .anyMatch(e -> "input".equals(e.getTagName())));
}
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: This suggestion correctly identifies that using findElement with a non-unique class name is brittle. The proposed change to use findElements and check for any match makes the test more robust and reliable.
Low
Refine XPath locator specificity
Refine the XPath locator in testXpath to be more specific by including the type='radio' attribute, preventing potential mismatches.
-WebElement element = driver.findElement(By.xpath("//input[@value='f']"));+WebElement element = driver.findElement(By.xpath("//input[@value='f' and @type='radio']"));
Apply / Chat
Suggestion importance[1-10]: 5
__
Why: This is a valid suggestion that improves the specificity and robustness of the XPath locator, which is a good practice for writing stable tests.
Low
Extract URL to constant
Extract the hard-coded URL in setUp to a private static final constant to improve maintainability.
-driver.get("https://www.selenium.dev/selenium/web/locators_tests/locators.html");+private static final String BASE_URL = "https://www.selenium.dev/selenium/web/locators_tests/locators.html";+...+driver.get(BASE_URL);
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 3
__
Why: This is a valid code style and maintainability suggestion. However, since the URL is used only once in the file, its impact is minor.
Low
More
rpallavisharma
changed the title
added locator file for java and added content in diff languages files
added locator code file for java for Locator Strategies Section and added content in diff languages files
Feb 6, 2026
rpallavisharma
changed the title
added locator code file for java for Locator Strategies Section and added content in diff languages files
added locator code file for java for locator strategies Section and added content in diff languages files
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
added locator code file for java for locator strategies Section and added content in diff languages files
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
Added java program for locators and added the code block in diff files
Motivation and Context
it wasn't there.
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Created comprehensive Java test class for locator strategies
Replaced inline code snippets with references to actual test methods
Updated documentation across multiple language files (English, Japanese, Portuguese, Chinese)
Removed old LocatorsTest.java file with ByAll and ByChained examples
Diagram Walkthrough
File Walkthrough
LocatorTest.java
New comprehensive Java locator test classexamples/java/src/test/java/dev/selenium/elements/LocatorTest.java
strategies
lifecycle management
tagName, and xpath locators
properties
LocatorsTest.java
Removed deprecated LocatorsTest fileexamples/java/src/test/java/dev/selenium/elements/LocatorsTest.java
locator strategy tests
locators.en.md
Updated Java examples with test file referenceswebsite_and_docs/content/documentation/webdriver/elements/locators.en.md
LocatorTest.java
partialLinkText, tagName, xpath) now links to corresponding test
method
examples
locators.ja.md
Updated Japanese locator documentation referenceswebsite_and_docs/content/documentation/webdriver/elements/locators.ja.md
LocatorTest.java
locators.pt-br.md
Updated Portuguese-Brazilian locator documentation referenceswebsite_and_docs/content/documentation/webdriver/elements/locators.pt-br.md
LocatorTest.java
structure
locators.zh-cn.md
Updated Chinese locator documentation referenceswebsite_and_docs/content/documentation/webdriver/elements/locators.zh-cn.md
LocatorTest.java
structure