1

The BiDi introduced in Selenium 4 sounds interesting. But when I turn it on with options.setCapability("webSocketUrl", true); I have trouble with Alert, Model, and Prompt. The old way driver.switchTo().alert() does not work as the Alert does not show up. Seems like I have to add a listener but it means I have to change a lot of code.

I tried adding a listener from devtool but it looks cubersome and will change a lot of existing script in my tests.

 DevTools devTools = ((ChromeDriver) webDriver).getDevTools();
 devTools.createSession();
 // Listen for JavaScript dialogs (alerts, confirms, prompts)
 devTools.send(Page.enable());
 devTools.addListener(Page.javascriptDialogOpening(), dialog -> {
 System.out.println("Alert Text: " + dialog.getMessage());
 devTools.send(Page.handleJavaScriptDialog(true, null)); // Accept the alert
 });

Is there any other way?

asked Dec 14, 2024 at 17:21
0

1 Answer 1

0
I have the same problem. Once I enable BiDi, modal dialogs don't appear anymore.
 ChromeOptions options = new ChromeOptions();
 //options.enableBiDi(); // uncomment this line to reproduce the error
 ChromeDriver driver = new ChromeDriver(options);
 driver.get("https://the-internet.herokuapp.com/javascript_alerts");
 driver.findElement(By.cssSelector("[onclick='jsAlert()']")).click();
 // throws "no such alert" if BiDi is enabled:
 Alert alert = driver.switchTo().alert();
 assertThat(alert.getText()).isEqualTo("I am a JS Alert");
answered Oct 24, 2025 at 8:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.