Selenium 指定浏览器位置

在脚本开头要指定浏览器位置.

 1 public static void main(String[] args) throws InterruptedException, IOException {
 2            System.setProperty("webdriver.gecko.driver", "D:\geckodriver-v0.19.1-win64\geckodriver.exe");
 3            ProfilesIni pi = new ProfilesIni();
 4            FirefoxProfile profile = pi.getProfile("default");
 5            FirefoxOptions options = new FirefoxOptions();
 6            options.setProfile(profile);
 7         WebDriver driver = new FirefoxDriver(options);
 8         driver.manage().window().maximize();
 9         driver.get("http://www.baidu.com");        
10         System.out.println(driver.getTitle());

不需要在脚本中指定浏览器位置的情形:

1. 浏览器安装在默认位置

2. 浏览器已添加在path中(i.e. 已配置环境变量)

原文地址:https://www.cnblogs.com/cheese320/p/8258086.html