【问题标题】:Unable to connect to Geckodriver无法连接到 Geckodriver
【发布时间】:2017-02-03 14:26:56
【问题描述】:

我正在尝试使用 Ruby on Rails 运行 Selenium 的示例脚本。我必须使用代理运行它。这是我的代码:

require 'rubygems'
require 'bundler/setup'

# require your gems as usual
require "selenium-webdriver"

Selenium::WebDriver::Firefox.path = "/home/marc/Documents/firefox/firefox"
profile = Selenium::WebDriver::Firefox::Profile.new
proxy = Selenium::WebDriver::Proxy.new(:http => nil)
profile.proxy = proxy
driver = Selenium::WebDriver.for :firefox, :profile => profile
driver.navigate.to "http://google.com"

element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit

puts driver.title

driver.quit

我收到以下错误:

/home/marc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.0.0.beta3.1/lib/selenium/webdriver/common/service.rb:115:in `connect_until_stable': unable to connect to Mozilla geckodriver 127.0.0.1:4445 (Selenium::WebDriver::Error::WebDriverError)

有人可以帮助我吗...?我从几个小时以来一直在尝试,但找不到问题......真的不知道该怎么办。

环境:

Ubuntu 16.04 LTS, 火狐 45.0, rbenv 2.3.1

其他问题:有人知道 Selenium + Ruby on Rails 的一些例子吗?我找不到真正好的东西......文档真的很差:(

【问题讨论】:

    标签: ruby-on-rails selenium selenium-webdriver geckodriver


    【解决方案1】:

    您有 selenium-webdriver-3.0.0.beta3.1,它仅适用于 Firefox 48 及更高版本(尚未正常工作)。 回退到selenium-webdriver 版本2.53.4 并重试。

    【讨论】:

    • 谢谢,我昨天自己解决了。但这正是我的问题,所以你是 100% 正确的。
    • 谢谢。我试图降级 Firefox 并安装 Gecko 驱动程序,但它没有用。我刚刚添加了“gem 'selenium-webdriver', '2.53.4'”并运行了 bundle update selenium-webdriver,它又可以工作了。
    • 问题是新版本的 selenium (> 3.0) 与旧版本的 Firefox (
    【解决方案2】:

    作为 DarKy 的 selenium 版本降级解决方案的补充:

    • 在终端更改目录路径到安装 gem 的目录
    • 运行gem uninstall selenium-webdriver
    • 运行gem install selenium-webdriver -v 2.53.4

    【讨论】:

      【解决方案3】:
      • 红宝石:红宝石 2.3.3p222
      • selenium-webdriver:selenium-webdriver (3.7.0)
      • 火狐:V57

      Selenium::WebDriver::Firefox.driver_path = "‪C:\\Users\\Desktop\\geckodriver.exe"
      capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
      driver = Selenium::WebDriver.for :firefox, desired_capabilities: capabilities
      driver.navigate.to "https://google.com"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-01
        • 2021-02-10
        • 2021-12-26
        • 1970-01-01
        • 2019-03-15
        • 1970-01-01
        • 2018-09-06
        • 1970-01-01
        相关资源
        最近更新 更多