Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/By.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected WebDriver getWebDriver(SearchContext context) {
protected JavascriptExecutor getJavascriptExecutor(SearchContext context) {
WebDriver driver = getWebDriver(context);

if (!(context instanceof JavascriptExecutor)) {
if (!(driver instanceof JavascriptExecutor)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. No cross-binding comparison noted 📘 Rule violation ≡ Correctness

This change alters user-visible Java behavior for relative locators by accepting wrapped contexts
whose unwrapped driver supports JavaScript, but the PR does not document any comparison with other
language bindings. Without an explicit cross-binding check, similar APIs may diverge in observable
behavior across Selenium bindings.
Agent Prompt
## Issue description
A user-visible behavior change was made in the Java binding (`By.getJavascriptExecutor()`), but there is no evidence in-code (comments/docs) that the behavior was compared with at least one other Selenium language binding as required.

## Issue Context
PR Compliance requires verifying cross-language consistency (or documenting intentional divergence) when changing user-visible behavior in a binding.

## Fix Focus Areas
- java/src/org/openqa/selenium/By.java[153-156]
- java/test/org/openqa/selenium/ByTest.java[188-199]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

throw new IllegalArgumentException(
"Context does not provide a mechanism to execute JS: " + context);
}
Expand Down
1 change: 1 addition & 0 deletions java/test/org/openqa/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ java_test_suite(
size = "small",
srcs = SMALL_TESTS,
deps = [
":helpers",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
"//java/test/org/openqa/selenium/netty/server:test-server",
Expand Down
36 changes: 36 additions & 0 deletions java/test/org/openqa/selenium/ByTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,40 @@ void ensureNameContainingBackslashIsEscapedAsLiteral() {
.containsEntry("using", "css selector")
.containsEntry("value", "*[name='a\\\\b']");
}

@Test
void getJavascriptExecutorAcceptsAContextWrappingAJavascriptCapableDriver() {
WebDriver driver = new StubDriver();

assertThat(By.cssSelector("cheese").getJavascriptExecutor(new DriverWrappingContext(driver)))
.isSameAs(driver);
}

/**
* Mirrors a context such as {@code RemoteWebElement}, which is not a {@link JavascriptExecutor}
* itself but wraps a driver that may be one.
*/
private static class DriverWrappingContext implements SearchContext, WrapsDriver {

private final WebDriver driver;

DriverWrappingContext(WebDriver driver) {
this.driver = driver;
}

@Override
public WebDriver getWrappedDriver() {
return driver;
}

@Override
public List<WebElement> findElements(By by) {
throw new UnsupportedOperationException("findElements");
}

@Override
public WebElement findElement(By by) {
throw new UnsupportedOperationException("findElement");
}
}
}