Selenium一直试图找到geckodriver,即使我认为我在使用Ruby 2.3.3时使用Chromedriver进行了设置

问题描述 投票:0回答:1

我正试图让Selenium使用Chrome(通过gem'chromedriver-helper'),所以我可以使用水豚。

但是,我在irb中遇到这个错误 - Selenium :: WebDriver :: Error :: WebDriverError:无法找到Mozilla geckodriver。请从https://github.com/mozilla/geckodriver/releases下载服务器并将其放在PATH的某个位置。更多信息在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.

我认为下面的片段告诉Selenium使用Chrome而不是Firefox !!

driver = Selenium::WebDriver.for:chrome

我期待 - 访问'http://capybaraworkout.herokuapp.com'带我到chrome中的URL(因为'visit'是一种水豚方法)我知道 - driver.get'http://capybaraworkout.herokuapp.com'会带我到URL,但是当我使用另一个水豚方法如 - click_link'开始锻炼!'我得到了同样的错误(Selenium :: WebDriver :: Error :: WebDriverError:无法找到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个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.