Chrome browser doesn't open in kiosk mode using Selenium WebDriver

╄→尐↘猪︶ㄣ 提交于 2019-12-13 03:49:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!