So was trying to implement BiDi Log in my project, for which I added the "webSocketUrl" capability as true in driver option.
But since then the anchor links in my code started behaving strangely in chromium browsers. As in when we click on the anchor link, the new tab is getting open, but after that browser gets stuck and does not load the url. Same code works fine
in firefox.
But when I set the "webSocketUrl" capability as false, or remove the same, the code starts working properly.
So I tried the same with simple java selenium code and was able to reproduce the same issue. Hope the sample code helps.
How can we reproduce the issue?
package com.seleniumtest.bugs;
import java.util.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.edge.*;
import org.openqa.selenium.firefox.*;
public class WebSocketUrlBug {
private static final int WAIT_FOR_MILLIS = 2000;
private static final String URL = "https://www.browserstack.com/";
static WebDriver driver = null;
public static void main(String[] args) {
openNewTabOrWinOnAnchorClick();
}
private static void openNewTabOrWinOnAnchorClick() {
try {
ChromeOptions options = new ChromeOptions();
// EdgeOptions options = new EdgeOptions();
// FirefoxOptions options = new FirefoxOptions();
options.setCapability("webSocketUrl", true); // <<<<< This causes the issue for Chromium browsers.
driver = new ChromeDriver(options); // 115.0.5790.171 // Not Working.
// driver = new EdgeDriver(options); // 115.0.1901.200 // Not Working.
// driver = new FirefoxDriver(options); // 102.14.0esr // Works fine.
driver.manage().window().maximize();
driver.get(URL);
WebElement ele = driver.findElement(By.partialLinkText("Register now"));
// ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", ele);
ele.click();
Thread.sleep(WAIT_FOR_MILLIS);
String mainHandle = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
System.out.println(handles);
String newHandle = "";
for (String handle : handles) {
if (!handle.equals(mainHandle)) {
newHandle = handle;
break;
}
}
driver.switchTo().window(newHandle);
Thread.sleep(WAIT_FOR_MILLIS);
driver.switchTo().window(mainHandle);
Thread.sleep(WAIT_FOR_MILLIS);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (driver != null) {
driver.quit();
}
}
}
}
Relevant log output
12:56:27 pm: Executing ':WebSocketUrlBug.main()'...
> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :WebSocketUrlBug.main()
Aug 10, 2023 12:56:33 PM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput
INFO: Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Aug 10, 2023 12:56:35 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 115, so returning the closest version found: 114
<<<<<<<<<<<<<<<<<<<<<<<<<<< Post browser is closed manually. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
java.lang.NullPointerException: Cannot invoke "java.util.Collection.size()" because "c" is null
at java.base/java.util.LinkedHashSet.<init>(LinkedHashSet.java:169)
at org.openqa.selenium.remote.RemoteWebDriver.getWindowHandles(RemoteWebDriver.java:459)
at com.seleniumtest.bugs.WebSocketUrlBug.openNewTabOrWinOnAnchorClick(WebSocketUrlBug.java:38)
at com.seleniumtest.bugs.WebSocketUrlBug.main(WebSocketUrlBug.java:14)
BUILD SUCCESSFUL in 34s
3 actionable tasks: 2 executed, 1 up-to-date
12:57:02 pm: Execution finished ':WebSocketUrlBug.main()'.
Operating System
Windows 10
Selenium version
Java 17 with Selenium 4.10, 4.11
What are the browser(s) and version(s) where you see this issue?
Chrome 115.0.5790.171, Edge 115.0.1901.200
What are the browser driver(s) and version(s) where you see this issue?
What happened?
Thank you so much for your time in advance.
So was trying to implement BiDi Log in my project, for which I added the "webSocketUrl" capability as true in driver option. But since then the anchor links in my code started behaving strangely in chromium browsers. As in when we click on the anchor link, the new tab is getting open, but after that browser gets stuck and does not load the url. Same code works fine in firefox.
But when I set the "webSocketUrl" capability as false, or remove the same, the code starts working properly. So I tried the same with simple java selenium code and was able to reproduce the same issue. Hope the sample code helps.
How can we reproduce the issue?
Relevant log output
Operating System
Windows 10
Selenium version
Java 17 with Selenium 4.10, 4.11
What are the browser(s) and version(s) where you see this issue?
Chrome 115.0.5790.171, Edge 115.0.1901.200
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 115.0.5790.171, EdgeDriver 115.0.1901.200
Are you using Selenium Grid?
NA