【问题标题】:Selenium keep trying to find geckodriver, even when I think I've set it up with Chromedriver while using Ruby 2.3.3Selenium 一直在尝试寻找 geckodriver,即使我认为我在使用 Ruby 2.3.3 时已经使用 Chromedriver 进行了设置
【发布时间】:2019-07-07 22:40:37
【问题描述】:

我正在尝试让 Selenium 使用 Chrome(通过 gem 'chromedriver-helper'),以便我可以使用 capybara。

但是,我一直在 irb 中遇到此错误 - Selenium::WebDriver::Error::WebDriverError: 无法找到 Mozilla geckodriver。请从https://github.com/mozilla/geckodriver/releases 下载服务器并将其放置在您的路径中的某个位置。更多信息请访问https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

我知道 Selenium 默认使用 Firefox 和 geckodriver,但是我的 iMac 不再获得 MacOS 更新,因此 brew 不会下载 geckodriver。 所以,我正在使用 chromedriver。

以下是我在 irb 中输入的内容。

2.3.3 :001 > require 'capybara/dsl'
 => true
2.3.3 :002 > require 'selenium-webdriver'
 => true
2.3.3 :003 > include Capybara::DSL
including Capybara::DSL in the global scope is not recommended!
 => Object
2.3.3 :004 > Capybara.default_driver = :selenium
 => :selenium
2.3.3 :005 > driver = Selenium::WebDriver.for:chrome
 => #<Selenium::WebDriver::Chrome::Driver:0x3f7ff1cdc18a3184 browser=:chrome>
2.3.3 :006 > visit 'http://capybaraworkout.herokuapp.com'
Selenium::WebDriver::Error::WebDriverError:  Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.

我认为下面的 sn-p 告诉 Selenium 使用 Chrome,而不是 Firefox!

driver = Selenium::WebDriver.for:chrome

我期待 - 访问'http://capybaraworkout.herokuapp.com' 带我到 chrome 中的 URL(因为“访问”是一种水豚方法) 我知道 - driver.get 'http://capybaraworkout.herokuapp.com' 会将我带到 URL,但是当我使用另一种水豚方法时 - click_link '开始锻炼!'我得到同样的错误(Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver。请从https://github.com/mozilla/geckodriver/releases 下载服务器并将其放置在您的PATH 中的某个位置。更多信息请参见https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver。)

我需要做什么才能让 Capybara 通过 Selenium 使用 Chrome?

【问题讨论】:

    标签: ruby selenium-webdriver selenium-chromedriver capybara


    【解决方案1】:

    您需要注册一个具有特定配置的驱动程序,以告诉 Capybara 使用不同的浏览器 - https://github.com/teamcapybara/capybara#configuring-and-adding-drivers。然而,如果你想要的只是 Selenium 使用 Chrome 和默认设置,那么 Capybara 已经为你注册了一个驱动程序 - https://github.com/teamcapybara/capybara#selenium

    Capybara.default_driver = :selenium_chrome
    

    这将要求您安装 chromedriver(chromedriver-helper gem 将为此做,尽管我建议使用 webdrivers gem 代替)。如果您不想使用 selenium/chromedriver,那么有几个较新的选项可以直接与 Chrome 对话,其中之一是 appartion 驱动程序 - https://github.com/twalpole/apparition

    【讨论】:

    • 难以置信!!老实说,我花了几个小时试图弄清楚。我确实看到了 github 页面,我想我离兔子洞太远了,无法理解它。再次感谢您的帮助。
    猜你喜欢
    • 2023-03-07
    • 2012-11-14
    • 2011-10-04
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    相关资源
    最近更新 更多