【问题标题】:Watir: set custom profile to watir firefox not workingWatir:将自定义配置文件设置为 watir firefox 不工作
【发布时间】:2018-04-16 01:53:14
【问题描述】:

我发现许多提示可以在 watir firefox 浏览器中实现自定义配置文件设置,但都不起作用。

隐私浏览设置:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.privatebrowsing.dont_prompt_on_enter'] = true
profile['browser.privatebrowsing.autostart'] = true
browser = Watir::Browser.new :firefox, :profile => profile

自动保存文件设置:

profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = path
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"
browser = Watir::Browser.new :firefox, :profile => profile

错误信息:

/var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/w3c_bridge.rb:80:in `initialize': unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile:0x000000016da348 @model=nil, @native_events=false, @secure_ssl=false, @untrusted_issuer=true, @load_no_focus_lib=false, @additional_prefs={"browser.privatebrowsing.dont_prompt_on_enter"=>true, "browser.privatebrowsing.autostart"=>true}, @extensions={}>} (ArgumentError)

可以在firefox上自定义设置吗?怎么了?

  • 女仆版本:6.0.2
  • 硒版本:3.0.1
  • 浏览器版本:Firefox 51.0.1
  • 浏览器驱动版本:geckodriver 0.11.1
  • 操作系统版本:Ubuntu 16.04.3 LTS

【问题讨论】:

    标签: ruby firefox watir watir-webdriver


    【解决方案1】:

    在 options.profile 中分配您的个人资料

    profile = Selenium::WebDriver::Firefox::Profile.new
    profile['browser.download.folderList'] = 2
    profile['browser.download.dir'] = path
    profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"
    options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
    browser = Watir::Browser.new :firefox, options: options
    

    【讨论】:

    • 谢谢,但这不起作用。错误信息:未初始化的常量 Selenium::WebDriver::Firefox::Options (NameError)
    • 您的项目中是否需要“selenium-webdriver”? github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#firefox
    • 不,我只需要 watir。我刚刚测试了另外需要“selenium-webdriver”,但出现了同样的错误消息。如果我禁用配置文件行,浏览器将毫无问题地启动。如果需要 watir,我认为没有必要包含 selenium-webdriver。
    • 如果需要 watir,则不需要 selenium-webdriver
    • 谢谢,但自定义配置文件设置仍然无效。
    猜你喜欢
    • 2015-12-24
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多