问题
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
I want to log in to Google using Selenium IDE but Google doesn't allow automation frameworks to log in. However, by using the above options it is possible to log in to Google.
The above options are defined for ChromeDriver
and I need to define them for FirefoxDriver
. How can I do that?
回答1:
To start with each passing day both GeckoDriver and ChromeDriver are evolving out to be more robust and compliant to the WebDriver Level 2 W3C Specifications.
However, the methods supported through ChromeOptions and FirefoxOptions are still a bit different.
Methods supported by FirefoxOptions()
addArguments(addArguments(java.lang.String... arguments)
addPreference(java.lang.String key, java.lang.String value)
merge(Capabilities capabilities)
setCapability(java.lang.String key, java.lang.Object value)
setHeadless(boolean headless)
setLegacy(boolean legacy)
setLogLevel(FirefoxDriverLogLevel logLevel)
setPageLoadStrategy(PageLoadStrategy strategy)
setProfile(FirefoxProfile profile)
setProxy(Proxy proxy)
setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour)
Methods supported by ChromeOptions()
addArguments(java.lang.String... arguments)
addExtensions(java.io.File... paths)
addEncodedExtensions(java.util.List<java.lang.String> encoded)
merge(Capabilities extraCapabilities)
setBinary(java.lang.String path)
setExperimentalOption(java.lang.String name, java.lang.Object value)
setHeadless(boolean headless)
setPageLoadStrategy(PageLoadStrategy strategy)
setProxy(Proxy proxy)
setUnhandledPromptBehaviour(UnexpectedAlertBehaviour behaviour)
So it is quite evident that though the methods supported by ChromeOptions()
and FirefoxOptions()
are almost similar but there are some distinct methods supported individually by them. setExperimentalOption(java.lang.String name, java.lang.Object value)
is one of them.
setExperimentalOption()
setExperimentalOption(java.lang.String name, java.lang.Object value) sets an experimental option. This method is useful for new ChromeDriver options not yet exposed through the ChromeOptions API.
public ChromeOptions setExperimentalOption(java.lang.String name, java.lang.Object value)
Conclusion
setExperimentalOption()
method is exclusively supported through ChromeOptions() only and isn't supported through FirefoxOptions().
来源:https://stackoverflow.com/questions/62553189/how-can-i-use-setexperimentaloption-through-options-using-firefoxdriver-in-selen