【发布时间】:2019-02-27 02:17:38
【问题描述】:
我无法在 Selenium Webdriver 3 中为 Firefox 设置默认配置文件,因为 FirefoxDriver 类中没有这样的构造函数。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SeleniumStartTest {
@Test
public void seleniumFirefox() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\FirefoxDriver\\geckodriver.exe");
ProfilesIni profileIni = new ProfilesIni();
FirefoxProfile profile = profileIni.getProfile("default");
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.google.com");
}
}
Java 代码中的编译错误: Java Code
Maven pom.xml 依赖:
Selenium 3.14.0
火狐版本: Firefox version 62.0.2
【问题讨论】:
-
您应该创建一个 FirefoxOptions 对象来设置配置文件。
FirefoxOptions fo = new FirefoxOptions(); fo.setProfile(profile); WebDriver driver = new FirefoxDriver(fo); -
好的,它有效。项目运行没有编译或运行时异常,但是火狐打开了2分钟,为什么要花这么多时间?也许还有其他解决方案。因为没有此配置文件设置,项目将在 10 秒内启动。
-
@VladyslavKuhivchak :理想情况下它应该在 10 秒内开始。你在个人资料中加载了什么?
标签: java selenium firefox geckodriver firefox-profile