简体   繁体   中英

How to open specific browser using Selenium webdriver

I am using lang :java framework: testNG

my system has 3-4 versions of Mozilla installed, how can i open instance of specific version of Mozilla. Suppose i have 3.5, 3.6,.... version of Mozilla installed and I want to open 3.6 version and perform my testing.

Just specify the path to the binary of the version..may be, like-

FirefoxBinary binary = new FirefoxBinary(new File("path_to_bin"));
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(binary, profile);

只需将正确版本的 firefox.exe 的路径分配给 webdriver.firefox.bin 属性即可。

System.setProperty("webdriver.firefox.bin", "c:\\path\\to\\firefox.exe");

For firefox

 System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
 WebDriver driver = new FirefoxDriver();

Fro Chrome browser

     File file = new File("D:\\selnium webdriver\\driver\\chromedriver.exe");
     System.setProperty("webdriver.chrome.driver", file.getAbsolutePath() );
      WebDriver driver = new ChromeDriver();

For Internet explorer

           File file = new File("D:\\selnium webdriver\\driver\\IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
       WebDriver driver = new InternetExplorerDriver();

For Ruby - Chrome

  caps = Selenium::WebDriver::Remote::Capabilities.chrome("desiredCapabilities" => "chromeOptions" => {"binary" => "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"})
  @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps
System.setProperty("webdriver.chrome.driver", "./chromedriver.exe");  //for chrome
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("WebsiteURL");


System.setProperty("webdriver.gecko.driver", "./geckodriver.exe");  //for firefox
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("WebsiteURL");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM