Tiffany G
Tiffany G

Reputation: 203

Selenium Webdriver Unable to create chrome webdriver instance

We've been running integration tests successfully against Ruby on Rails 2 using Selenium on both Google Chrome and Firefox. However, we've recently upgraded to Ruby on Rails 3 and are running into issues creating a Google Chrome webdriver instance.

When we attempt to create, we get the following stack:

irb(main):002:0> profile = Selenium::WebDriver::Chrome::Profile.new
translate])#<Selenium::WebDriver::Chrome::Profile:0x64f2fd0 @extensions=[], @model=nil>
irb(main):003:0> profile['download.prompt_for_download'] = false
false
irb(main):004:0> driver = Selenium::WebDriver.for(:chrome, :profile  => profile,     :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate])
ArgumentError: wrong number of arguments (0 for 1)
  from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `open'
  from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `ip'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:170:in `interfaces'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:23:in `free?'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:5:in `above'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/service.rb:33:in `default_service'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/bridge.rb:14:in `initialize'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `new'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `for'
    from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver.rb:67:in `for'
    from (irb):4

Any tips?

Upvotes: 3

Views: 3382

Answers (3)

ChromeDriver Installation:

Download Chromedriver 2.x from "http://chromedriver.storage.googleapis.com/index.html?path=2.8/."

Unzip it and save it in a folder on any drive. Set path by the following steps:

  • Copy the path till chromedriver.exe
  • Right click on Computer and select ‘Properties’
  • Select ‘Advanced system variables’
  • Select ‘Environment variables’
  • Click on Edit button for ‘Path’ variable of ‘User variables’
  • Append the chromedriver path
  • Save changes.

Run Selenium Test:

Now run your Selenium test. It will run in the Chrome browser.

Sample Code

require 'selenium-webdriver'
$driver = Selenium::WebDriver.for :chrome
$driver.navigate.to "https://www.google.co.in/"
$driver.manage().window().maximize()
$driver.quit()

Note: You need to install the latest chromedriver for the latest version of the Chrome browser

Upvotes: 1

techpeace
techpeace

Reputation: 2644

I saw this when I had included a gem which included the backports gem as part of its dependencies into my Gemfile. The backports gem rewrites some Ruby 1.8 internals, which overwrote parts of the UDPSocket core class. Try getting rid of the backports gem and giving it a shot.

Upvotes: 3

Marc-Andr&#233; Lafortune
Marc-Andr&#233; Lafortune

Reputation: 79562

This was caused by an interference with the backports gem and the fact that the socket library reuses IO.open although it changes the interface.

Upgrading backports to v2.6.7 or above should resolve this.

Upvotes: 0

Related Questions