Open
Description
What happened?
While teaching a class about test automation to the students of Saudi Digital Academy we wrote this code:
public class RelativeLocatorsTabularTests {
WebDriver driver;
@Test
public void checkContactNameForTargetCompany(){
// TODO: Report Bug to Selenium Team
By contactNameForTargetCompany =
RelativeLocator.with(By.tagName("td"))
.toRightOf(By.xpath("//td[text()='Alfreds Futterkiste']"))
.below(By.xpath("//th[text()='Contact']"));
var actualName = driver.findElement(contactNameForTargetCompany).getText();
Assertions.assertEquals("Maria Anders", actualName);
}
@BeforeEach
public void beforeEach(){
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.w3schools.com/html/html_tables.asp");
}
@AfterEach
public void afterEach(){
driver.quit();
}
}
We expected to locate the name of the Contact but the actual behavior was that it located the name of the Country (Germany).
This is the website we used to test: https://www.w3schools.com/html/html_tables.asp
Here's a screenshot of the target element and page dom:

How can we reproduce the issue?
You can use the same code snippet and it will work as-is
Relevant log output
N/A - we debugged it and found that selenium read the value Germany, but we didn't dive deeper
Operating System
Windows 11
Selenium version
Java 4.18.1
What are the browser(s) and version(s) where you see this issue?
Chrome 122.0.6261.70 (Official Build) (64-bit)
What are the browser driver(s) and version(s) where you see this issue?
Selenium Manager is downloading it automatically
Are you using Selenium Grid?
No