栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件?

当您按照FirefoxDriver类使用
Selenium 3.14.0时
,有效的构造函数为:

  • 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
    ===============================================



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455073.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号