Java selenium 3.6.0无法设置Profile

时间:2017-10-03 06:04:20

标签: java selenium

所以我下载了新版本的selenium(3.6.0),并且在获取firefox的配置文件时遇到了问题。最初我让它与3.5.3一起工作,但我现在不知所措..我已经尝试了所有我能想到的并且在这些论坛上无济于事!

我正在尝试加载用户个人资料“Selenium” - 我试过了

ProfilesIni profile = new ProfilesIni();
 FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
 WebDriver driver = new FirefoxDriver(ffprofile);

和这个

  ProfilesIni profile = new ProfilesIni();
    FirefoxProfile profile = listProfiles.getProfile("Selenium");
    WebDriver driver = new FirefoxDriver(profile);

我也尝试将Firefox配置文件设置为默认值,以便它只打开一个,但我现在看到selenium会为每个实例创建一个匿名配置文件。 这之前有用,但我看到它现在已经折旧了。我无法弄清楚如何使用FirefoxOptions打开配置文件。如果你能指出我正确的方向,那将是伟大的!我已经尝试了发布更新中的java示例,但它无法正常工作..

我搜索了谷歌上的每个链接,因为很多相关内容,根本无法找到可行的方法。一切都在让我回想起我现在这样做的方式是折旧的.. 感谢

4 个答案:

答案 0 :(得分:1)

当您使用最新版本的selenium时,我建议您在org.openqu.selenium.remote包中使用DesiredCapabilities,您的jdk合规级别应为1.8。

System.setProperty("webdriver.gecko.driver","path_to_geckodriver.exe");
    File file = new File(path_to_your_firefox_profile);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile(file);
    dc.setCapability(FirefoxDriver.PROFILE, profile);
    FirefoxDriver driver = new FirefoxDriver(dc);
    driver.get("https://www.google.com");

System.setProperty("webdriver.gecko.driver","path_to_geckodriver.exe"); File file = new File(path_to_your_firefox_profile); DesiredCapabilities dc = DesiredCapabilities.firefox(); FirefoxProfile profile = new FirefoxProfile(file); dc.setCapability(FirefoxDriver.PROFILE, profile); FirefoxDriver driver = new FirefoxDriver(dc); driver.get("https://www.google.com"); 有关详细信息,请参阅此博客。 http://himanshuupadhyay.blogspot.com/2014/01/firefox-webdriver-profile-desired.html

让我知道这对你有用。

答案 1 :(得分:1)

所有答案都完全忽略了“ setProfile”问题。 答案是如何实现“ setProfile”:

ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile myProfile = allProfiles.getProfile("Selenium"); 
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(myProfile);
WebDriver driver = new FirefoxDriver(firefoxOptions);

答案 2 :(得分:0)

可能的原因是changelog表示3.6.0 -

  • 所有Option班级现已延长MutableCapbilities new RemoteWebDriver(new ChromeOptions());
  • 弃用不采用强类型Options的构造函数。

答案 3 :(得分:0)

我正在使用selenium WebDriver 3.7.1我正在为firefox配置文件编写代码,它将在firefox版本57.0.2上运行。

步骤1:按类型命令“firebox.exe -p”创建Firefox配置文件,将配置文件名称创建为“myprofile”。 第2步:按照以下代码

System.setProperty("webdriver.gecko.driver","P:\\javaapi\\geckodriver-v0.19.1-win64\\geckodriver.exe");
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile FF = new FirefoxProfile(new File("C:\\Users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\es610sjr.myprofile")); // path to firefox profile
dc.setCapability(FirefoxDriver.PROFILE, FF);
driver = new FirefoxDriver(dc);
driver.get("https://www.google.com");