2

I want to automatically open a browser with an URL in java. The browser should open in full-screen ( --kiosk) mode and --incognito mode together.
Currently, I am using following code to automatically open a browser. if(Desktop.isDesktopSupported()){ Desktop.getDesktop().browse(new URI("http://www.google.com")); }

Note: I am not using selenium webdriver. How could I fix such issue? Thanks in advance.

  • you want something related to webdrivers selenium? – Kushal Bhalaik Apr 27 '17 at 16:17
  • I don't think that this will work with `Desktop.getDesktop().browse()`. This is passed to the configured default browser and there is no guarantee that the default browser honours these flags. If you know the system the program is running on and which browsers are installed you might explicitly launch a browser with the required arguments. – P.J.Meisch Apr 27 '17 at 18:10
  • Say, I explicitly launch chrome browser. Could you please share codes need to run for required arguments? – Touhidul Islam Apr 27 '17 at 21:00

2 Answers2

1

Got a solution without selenium web driver.

String cmd = "chromium-browser --incognito --kiosk http://example.com/";
Runtime run = Rintime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
0

Using selenium webdriver

DesiredCapabilities desiredcapabilities=DesiredCapabilities.chrome();
    ChromeOptions option=new ChromeOptions();
    option.addArguments("--incognito");
    desiredcapabilities.setCapability(ChromeOptions.CAPABILITY,option );
    System.setProperty("webdriver.chrome.driver", 
   "Path_of_driver\\chromedriver.exe");
    WebDriver driver=new ChromeDriver(desiredcapabilities);
    driver.manage().window().maximize();
    driver.get("https://www.google.co.in");
Kuldeep Yadav
  • 107
  • 1
  • 14