Selenium 设定firefox的启动路径(安装多个firefox适用)

Firefox版本过高,不兼容,启动会报错,所以可安装多个版本的Firefox

 

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class baidu {

public static void main(String[] args) {
// TODO Auto-generated method stub

//如果安装了一个Firefox,下面这句可省略
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.baidu.com/");
String url=driver.getCurrentUrl();
System.out.println(url);
driver.close();
}

}

 

 

 

启动谷歌浏览器的方法

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Chrome {

public static void main(String[] args) {
// TODO Auto-generated method stub
//把chromdriver拷贝到谷歌安装目录下,通过谷歌路径启动
/* System.setProperty ( "webdriver.chrome.driver" , "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe" );

WebDriver driver = new ChromeDriver();
*/

//通过路径启动Chrome
String chrome_path = System.getProperty("user.dir") + "/driver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver",chrome_path);
WebDriver driver = new ChromeDriver();

driver.get("http://www.baidu.com/");
driver.manage().window().maximize();
}

}

 

 

 

 

 

 

 

 

启动IE浏览器的方法

 

import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;;
public class Ie {

public static void main(String[] args) {
// TODO Auto-generated method stub

//下方路径为IE驱动的路径,也可以在环境变量path配置,就不需要这句了
System.setProperty ( "webdriver.ie.driver" , "D:\\Program Files\\ESworkspace\\WLS\\driver\\IEDriverServer.exe" );

WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com/");
}

}

posted @ 2016-08-05 14:56  菜猫猫  阅读(3052)  评论(0编辑  收藏  举报