我尝试了以下代码
crawler = Capybara::Session.new(:selenium)
crawler.visit "https://twitter.com" # Error this line!
与
gem: capybara (= 2.2.0) selenium-webdriver (3.3.0) WebBrowser: FireFoex53.0 OS: Mac OSX
然后得到以下错误
TypeError: can't dup NilClass
[stack trace]
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_capabilities.rb:101:in `dup'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_capabilities.rb:101:in `json_create'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:116:in `create_session'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:76:in `initialize'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/firefox/w3c_bridge.rb:45:in `initialize'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:52:in `new'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/driver.rb:52:in `for'",
gems/selenium-webdriver-3.3.0/lib/selenium/webdriver.rb:87:in `for'",
gems/capybara-2.2.0/lib/capybara/selenium/driver.rb:13:in `browser'",
gems/capybara-2.2.0/lib/capybara/selenium/driver.rb:45:in `visit'",
gems/capybara-2.2.0/lib/capybara/session.rb:197:in `visit'"
当我在这个FireFox浏览器上进行手动访问时,url“https://twitter.com”正在运行。
但是水豚的visit
方法不起作用..
答案 0 :(得分:1)
我在尝试使用selenium-webdriver
gem as instructed时遇到了这个错误( TypeError:不能复制NilClass ):
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
作为suggested by Thomas,将selenium-webdriver
gem编号从3.3.x更新为3.4.x可以解决问题。