1
嘗試寫對谷歌一個簡單的例子水豚,但得到未定義的方法`參觀」的硒:: webdriver的::驅動
undefined method `visit' for #<Selenium::WebDriver::Driver:0x000000055f8cc8>
我可以使用
driver.get("http://www.google.com/")
,但我不能使用
driver.visit("http://www.google.com/")
我:
require "rspec"
require 'selenium-webdriver'
require "capybara"
require "capybara/rspec"
require "capybara/dsl"
RSpec.configure do |config|
config.include Capybara::DSL
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :selenium
config.app_host = 'https://www.google.com'
end
describe "Google Search", type: :feature do
it "Tests Google" do
driver = Selenium::WebDriver.for :chrome
driver.visit "http://www.google.com/" <-- Error
fill_in('input', with: '123')
find_element('input', "Google Search").click
driver.quit
end
end
請注意,我必須使用chrome,因爲我的硒火狐設置不同步(隨着時間的推移常見問題 - 它無法在60秒內啓動firefox)。但鉻作品和瀏覽器出現。
這個簡單的紅寶石唯一的例子確實然而工作,所以看起來像某種RSpec的安裝問題的
require 'rubygems'
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.get "http://google.com"
element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit
puts "Page title is #{driver.title}"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.title.downcase.start_with? "cheese!" }
puts "Page title is #{driver.title}"
driver.quit