【问题标题】:FirefoxDriver always starting on "firstrun" page, breaking all test scriptsFirefoxDriver 总是从“firstrun”页面开始,破坏所有测试脚本
【发布时间】:2016-03-08 06:10:50
【问题描述】:

从昨晚开始,FirefoxDriver 一直在此页面上打开:https://www.mozilla.org/en-US/firefox/42.0/firstrun/learnmore/。我已尝试更改默认配置文件设置,但没有任何成功。

下面的问题http://stackoverflow.com/questions/33937067/firefox-webdriver-opens-first-run-page-all-the-time 类似,但是我看不到在哪里实现这四行代码,而且我个人尝试将其放入脚本中的尝试被证明是徒劳的。

这个问题昨晚开始完全出乎意料。我今天要进行演示,但我的任何脚本都无法运行。

像这样实例化我的 WebDriver 实例会导致 NoSuchMethodError:

                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("browser.startup.homepage", "about:blank");
                profile.setPreference("startup.homepage_welcome_url", "about:blank");
                profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
                driver = new FirefoxDriver(profile);
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

但是在FirefoxDriver 中删除profile 会将它带回到上面提到的第一个运行页面。

【问题讨论】:

    标签: firefox selenium


    【解决方案1】:

    我在使用 Selenium Webdriver 和 Poltergeist 和 Firefox 作为 Rails 应用程序的浏览器运行 RSpec/Capybara 测试时遇到了这个问题。尝试以各种方式重新配置 Firefox 无济于事,但通过简单地更新我的 Gemfile (gem 'selenium-webdriver') 中的 selenium-webdriver gem 来修复:

    bundle update selenium-webdriver

    感谢@lucetzer

    【讨论】:

      【解决方案2】:

      我在第一次运行页面时遇到了同样的问题,经过一番搜索后我发现这对我有用(我使用 WebDriver 2.53.0 和 FF 45.0.1):

      FirefoxProfile profile = new FirefoxProfile();
      profile.setPreference("browser.startup.homepage_override.mstone", "ignore");
      profile.setPreference("startup.homepage_welcome_url", "about:blank");
      profile.setPreference("startup.homepage_welcome_url.additional","about:blank");
      profile.setPreference("browser.startup.homepage","about:blank");
      WebDriver driver = new FirefoxDriver(profile);
      

      【讨论】:

        【解决方案3】:

        使用“Firefox.exe - p”转到配置文件管理器

        您将拥有多个个人资料。请选择默认配置文件并使其始终默认。

        它不应该打开那个页面。我测试过,效果很好。

        你可以试试这个代码。我很确定它会起作用。

            ProfilesIni profile = new ProfilesIni();
            FirefoxProfile ffprofile = profile.getProfile("default");
            WebDriver driver = new FirefoxDriver(ffprofile);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        

        【讨论】:

        • 我遇到了和@jagdpanzer 一样的问题。我只有一个默认的 Firefox 配置文件(遵循他们的指南:support.mozilla.org/en-US/kb/…)。您能否指定应该在哪里使用此代码以及它是位于现有文件中还是新创建的文件中(在哪种情况下,它的名称应该是特定的)?谢谢。
        • 默认配置文件始终存在。大部分时间代码用于在默认配置文件设置下打开 Firefox 并避免所有其他扩展加载。
        • 我只有一个配置文件。但首次运行页面仍然打开
        • 您是否创建了默认配置文件并尝试使用它?
        【解决方案4】:

        Mozilla 主页的首次运行初始屏幕中的证书存在问题。我在 Bugzilla 中为此提交了一张票:https://bugzilla.mozilla.org/show_bug.cgi?id=1269500

        要在 Selenium/Capybara/Cucumber 中解决此问题,我们需要将新配置文件的默认主页更改为空白或其他页面。为此,请在配置中注册您的 firefox/selenium 驱动程序:

        Capybara.register_driver :firefox do |app|
          profile = Selenium::WebDriver::Firefox::Profile.new
          profile['browser.startup.homepage_override.mstone'] = 'ignore'
          profile['startup.homepage_welcome_url.additional'] = 'about:blank'
        
          Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
        end
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-01-19
          • 2019-02-24
          • 2011-10-28
          • 2020-07-01
          • 1970-01-01
          • 2016-03-03
          • 2017-09-10
          相关资源
          最近更新 更多