我正在尝试使用 selenium4 和远程驱动程序访问 devtool,但我面临空指针异常。我在本地也试过了,效果很好
logger.info("##### Running web tests on (remote) ####");
String environment = System.getProperty("environment");
final ChromeOptions chromeOptions = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("googlegeolocationaccess.enabled", false);
prefs.put("profile.default_content_setting_values.geolocation", 2); // 1:allow 2:block
prefs.put("profile.default_content_setting_values.notifications", 1);
prefs.put("profile.managed_default_content_settings", 1);
chromeOptions.setExperimentalOption("prefs", prefs);
chromeOptions.setAcceptInsecureCerts(true);
chromeOptions.addArguments(
"--ignore-certificate-errors",
"--disable-download-notification",
"--no-sandbox",
"--disable-site-isolation-trials",
"--enable-strict-powerful-feature-restrictions",
"--disable-geolocation",
"--disable-gpu");
ChromeDriverService service;
try {
setupChromeDriverBinary();
service = new ChromeDriverService.Builder()
.usingAnyFreePort()
.build();
service.start();
dc.setCapability(CapabilityType.BROWSER_VERSION, "94");
dc.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
dc.setCapability("testName", "SpecSavers: End to End");
dc.setCapability("accessKey", "XXXXX");
driver = new RemoteWebDriver(new URL("https://XXXX/wd/hub"), dc);
} catch (Exception e) {
logger.error("Error due to " + e.getMessage());
throw new UnreachableBrowserException(e.getMessage());
}
return driver;