如何为默认Web浏览器和操作系统初始化Selenium驱动程序

时间:2014-01-29 21:20:54

标签: java selenium selenium-webdriver

在我的程序中,我们正在使用linux操作系统为firefox创建selenium webdriver。我想知道是否有任何方法可以创建将初始化为默认操作系统和Web浏览器的驱动程序。

   protected static WebDriver driver = init();



private static WebDriver init()
   {
      DesiredCapabilities capability = DesiredCapabilities.firefox(); // I want 
to detect the default browser of OS
      capability.setPlatform(Platform.LINUX);//it should automatically find the OS.

  WebDriver driver = init(BrowserType.FIREFOX);//Same here for initializing default web browser.

  driver.manage()
        .deleteAllCookies();
  driver.manage()
        .timeouts()
        .pageLoadTimeout(50, TimeUnit.SECONDS);
  driver.manage()
        .timeouts()
        .implicitlyWait(10, TimeUnit.SECONDS);
  driver.manage()
        .window()
        .maximize();
  return driver;

}

1 个答案:

答案 0 :(得分:0)

据我所知,以下选项适用于Windows和Linux:

选项#1 - 在正常模式下打开:

WebDriver webDriver = new FirefoxDriver();

选项#1 - 在无头模式下打开:

FirefoxBinary binary = new FirefoxBinary(new File("your/firefox/path"));
binary.setEnvironmentProperty("DISPLAY",System.getProperty("lmportal.xvfb.id",":99"));
WebDriver webDriver = new FirefoxDriver(binary,null);
相关问题