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?
1 Answer 1
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
Andrei Solntsev
5102 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.