我如何设置在硒的webdriver 3 Firefox的驱动程序默认的配置文件?

Vladyslav Kuhivchak:

因为在没有这样的构造,我不能设置为Firefox默认的配置文件中硒的webdriver 3 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代码的

Maven的pom.xml依赖关系:硒3.14.0

Firefox的版本:Firefox的版本62.0.2

DebanjanB:

当您使用硒3.14.0为每FirefoxDriver类有效的构造函数为:

  • FirefoxDriver()
  • FirefoxDriver(FirefoxOptions options)
  • FirefoxDriver(GeckoDriverService service)
  • FirefoxDriver(GeckoDriverService service, FirefoxOptions options)
  • FirefoxDriver(XpiDriverService service)
  • FirefoxDriver(XpiDriverService service, FirefoxOptions options)

所以,按你的代码尝试以下不调用有效选项 FirefoxDriver()

WebDriver driver = new FirefoxDriver(profile);

要调用调用FirefoxDriver()默认的配置文件,你需要使用setProfile(profile)方法来设置FirefoxProfile通过一个实例FirefoxOptions(),你可以使用下面的代码块:

  • 代码块:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.firefox.ProfilesIni;
    import org.testng.annotations.Test;
    
    public class A_FirefoxProfile {
    
          @Test
          public void seleniumFirefox() {
            System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
            ProfilesIni profileIni = new ProfilesIni();
            FirefoxProfile profile = profileIni.getProfile("default");
            FirefoxOptions options = new FirefoxOptions();
            options.setProfile(profile);
            WebDriver driver = new FirefoxDriver(options);
            driver.get("http://www.google.com");
            System.out.println(driver.getTitle());
          }
    
    }
    
  • 控制台输出:

    [RemoteTestNG] detected TestNG version 6.14.2
    1537775040906   geckodriver INFO    geckodriver 0.20.1
    1537775040923   geckodriver INFO    Listening on 127.0.0.1:28133
    Sep 24, 2018 1:14:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    Google
    PASSED: seleniumFirefox
    
    ===============================================
        Default test
        Tests run: 1, Failures: 0, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 0
    ===============================================
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Windows 10中删除重复的驱动程序配置文件?

如何在硒中正确设置Firefox配置文件?

Firefox硒驱动程序

Firefox配置文件设置使用硒webdriver配置在量角器中引发错误

驱动硒的配置文件

如何在使用chrome驱动程序/ firefox驱动程序时更改Webdriver中的文件下载位置

为什么我的 Boto3 脚本只针对我的默认配置文件运行?

如何关闭硒3中的木偶/壁虎驱动程序日志

如何在硒中设置firefoxdriver的驱动程序路径

如何设置默认配置文件弹簧

如何设置默认的终端配置文件?

为什么总是硒创建临时Firefox配置使用网络驱动程序?

如何使用默认的声音驱动程序

如何在使用Ruby的Selenium WebDriver远程上设置Firefox配置文件

如何配置图形驱动程序?

如何在单独的驱动器/分区上使用Firefox 4配置文件

设置Pulseaudio的默认配置文件

在Thunderbird中设置默认配置文件

如何在Selenium Webdriver Python 3中使用Chrome配置文件

如何修改Watir-Webdriver使用的Firefox配置文件

如何设置WebDriver IO的配置文件位置

如何获得默认的tmux配置文件?

FireFox壁虎驱动程序硒中不可调用

我如何在硒python 3中重新定位/禁用GeckoDriver的日志文件?

如何将数据从 Firefox 配置文件文件夹提供给扩展程序

在函数中调用驱动程序时,如何在 Python3 中保持 Selenium Webdriver 浏览器打开?

为什么内核使用默认的块驱动程序而不是我的驱动程序代码?

如何安装驱动程序文件?

如何在python 3中编辑xml配置文件?