org.openqa.selenium.InvalidArgumentException:使用 DesiredCapabilities 的无效功能
org.openqa.selenium.InvalidArgumentException: Invalid capabilities using DesiredCapabilities
我已经将我的 Selenium 框架升级到最新版本。在执行代码期间,我收到以下异常:
异常:
org.openqa.selenium.InvalidArgumentException:
Invalid capabilities in alwaysMatch: unhandledPromptBehavior is type boolean instead of string
详情:
- 硒:3.7.1;
- IE:3.7.0(32 位驱动程序);
- java.version: '1.8.0_144'.
而且较新的版本建议 driver = new InternetExplorerDriver(capabilities);
已弃用。我在函数中单独设置浏览器的功能,并将其作为参数传递给驱动程序。
如何解决这个问题?
代码片段:
desiredCapabilities(browser);
IE Capabilities Setting:-
capabilities = new DesiredCapabilities().internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true);
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true);
capabilities.setCapability("nativeEvents", false);
capabilities.setCapability("requireWindowFocus", false);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", ieExe.getAbsolutePath());
然后我调用我的驱动程序:
driver = new InternetExplorerDriver(capabilities);
好吧,来自 v3.7
的 Selenium
实现不再接受 DesiredCapabilities
类型对象作为参数来初始化 Web Browser
实例,而不是强类型 Options
类 是首选。所以你必须使用 InternetExplorerOptions
Class 对象,使用 merge
参数来自 MutableCapabilities
并作为参数传递。您的代码块将如下所示:
System.setProperty("webdriver.ie.driver", "C:\Utility\BrowserDrivers\IEDriverServer.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS", true);
capabilities.setCapability("ACCEPT_SSL_CERTS", true);
capabilities.setCapability("SUPPORTS_ALERTS", true);
capabilities.setCapability("UNEXPECTED_ALERT_BEHAVIOR", true);
capabilities.setCapability("IE_ENSURE_CLEAN_SESSION", true);
capabilities.setCapability("ENABLE_ELEMENT_CACHE_CLEANUP", true);
capabilities.setCapability("nativeEvents", false);
capabilities.setCapability("requireWindowFocus", false);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
InternetExplorerOptions opt = new InternetExplorerOptions();
opt.merge(capabilities);
WebDriver driver = new InternetExplorerDriver(opt);
我已经将我的 Selenium 框架升级到最新版本。在执行代码期间,我收到以下异常:
异常:
org.openqa.selenium.InvalidArgumentException:
Invalid capabilities in alwaysMatch: unhandledPromptBehavior is type boolean instead of string
详情:
- 硒:3.7.1;
- IE:3.7.0(32 位驱动程序);
- java.version: '1.8.0_144'.
而且较新的版本建议 driver = new InternetExplorerDriver(capabilities);
已弃用。我在函数中单独设置浏览器的功能,并将其作为参数传递给驱动程序。
如何解决这个问题?
代码片段:
desiredCapabilities(browser);
IE Capabilities Setting:-
capabilities = new DesiredCapabilities().internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
capabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true);
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true);
capabilities.setCapability("nativeEvents", false);
capabilities.setCapability("requireWindowFocus", false);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", ieExe.getAbsolutePath());
然后我调用我的驱动程序:
driver = new InternetExplorerDriver(capabilities);
好吧,来自 v3.7
的 Selenium
实现不再接受 DesiredCapabilities
类型对象作为参数来初始化 Web Browser
实例,而不是强类型 Options
类 是首选。所以你必须使用 InternetExplorerOptions
Class 对象,使用 merge
参数来自 MutableCapabilities
并作为参数传递。您的代码块将如下所示:
System.setProperty("webdriver.ie.driver", "C:\Utility\BrowserDrivers\IEDriverServer.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS", true);
capabilities.setCapability("ACCEPT_SSL_CERTS", true);
capabilities.setCapability("SUPPORTS_ALERTS", true);
capabilities.setCapability("UNEXPECTED_ALERT_BEHAVIOR", true);
capabilities.setCapability("IE_ENSURE_CLEAN_SESSION", true);
capabilities.setCapability("ENABLE_ELEMENT_CACHE_CLEANUP", true);
capabilities.setCapability("nativeEvents", false);
capabilities.setCapability("requireWindowFocus", false);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
InternetExplorerOptions opt = new InternetExplorerOptions();
opt.merge(capabilities);
WebDriver driver = new InternetExplorerDriver(opt);