在脚本开头要指定浏览器位置.
public static void main(String[] args) throws InterruptedException, IOException {
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.19.1-win64\\geckodriver.exe");
ProfilesIni pi = new ProfilesIni();
FirefoxProfile profile = pi.getProfile("default");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
driver.manage().window().maximize();
driver.get("http://www.baidu.com");
System.out.println(driver.getTitle());
不需要在脚本中指定浏览器位置的情形:
1. 浏览器安装在默认位置
2. 浏览器已添加在path中(i.e. 已配置环境变量)