问题
I am using Selenium WebDriver with chrome browser and for whatever reason, it doesn't open in kiosk mode. This used to work, not sure why it stopped.
This is my code:
private IWebDriver GetChromeDriver(BrowserConfigurationOptions browserConfigOptions)
{
var options = new ChromeOptions();
options.AddArguments("disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);
if (browserConfigOptions.KioskModeForChrome)
options.AddArgument("--kiosk"); //options.AddArgument("--enable-kiosk-mode");
LogChromeOptions(options);
return new ChromeDriver(options);
}
This is my environment:
- Chrome 66
- Selenium WebDriver v 3.11.2
- Chromedriver version 2.38.0.1 from this Nuget package
I've tried passing in --kiosk and --enable-kiosk-mode with no success.
回答1:
After seeing that everyone had this working except me, I started digging further. After digging into the code I found
Driver.Manage().Window.Maximize();
being called after initialization of the driver. After removing this line of code, I was able to open Chrome in kiosk mode with the solution above.
回答2:
Config issue as Chrome 66 is supported by Chromedriver 2.38 and you're using 2.18
Please update from below.
http://chromedriver.chromium.org/downloads
回答3:
To initialize the Chrome Browser in Kiosk Mode you need to pass the following argument through an instance of ChromeOptions class:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
return new ChromeDriver(options);
Note A : As per Java Doc, it is arguments are passed as addArguments()
Note B : As per Peter Beverloo
--kiosk:Enables kiosk mode. Please note this is not Chrome OS kiosk mode.Sample Code(Java):
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--kiosk"); WebDriver driver = new ChromeDriver(options); driver.get("https://www.google.com/");Browser Snapshot:
来源:https://stackoverflow.com/questions/50609245/chrome-browser-doesnt-open-in-kiosk-mode-using-selenium-webdriver