I've looked at so many suggested solutions to this issue, and yet none apply or have worked for me. I'm trying to test updating chromedriver and google-chrome on our staging server and having no luck.
We were using an older version of selenium-webdriver, so I updated as far as we could go (we are on Ruby 2.3.6), so our versions stand at:
selenium-webdriver: 3.142.7
capybara: 2.7.1
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 5.4.0-1093-aws
Architecture: x86-64
$ which chromedriver
/usr/bin/chromedriver
$ which google-chrome
/usr/bin/google-chrome
$ chromedriver --version
ChromeDriver 109.0.5414.74 (e7c5703604daa9cc128ccf5a5d3e993513758913-refs/branch-heads/5414#{#1172})
$ google-chrome --version
Google Chrome 109.0.5414.74
I've been running it somewhat like this. I added the Service instance after moving to selenium webdriver 3.142.7
def set_defaults
options = set_options
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: options)
service = Selenium::WebDriver::Service.chrome(path: '/usr/bin/chromedriver')
selenium_options = { browser: :chrome, desired_capabilities: capabilities, service: service }
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, selenium_options)
end
Capybara.javascript_driver = :chrome
end
def set_options
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0'
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument("--user-agent='#{user_agent}'")
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-gpu')
options.add_argument('--window-size=1280,1024')
options.add_argument('--disable-dev-shm-usage') # I added this after reading other answers on SO, but it didn't make a difference
options
end
The vast majority of this was set up previously and working until we needed to update our chromedriver/google-chrome versions, which is what I'm testing.
Here is the error I'm seeing when trying to run the above code:
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
from #0 0x55b693029303 <unknown>
from #1 0x55b692dfdd37 <unknown>
from #2 0x55b692e26157 <unknown>
from #3 0x55b692e22330 <unknown>
from #4 0x55b692e634a6 <unknown>
from #5 0x55b692e5a753 <unknown>
from #6 0x55b692e2da14 <unknown>
from #7 0x55b692e2eb7e <unknown>
from #8 0x55b69307832e <unknown>
from #9 0x55b69307bc0e <unknown>
from #10 0x55b69305e610 <unknown>
from #11 0x55b69307cc23 <unknown>
from #12 0x55b693050545 <unknown>
from #13 0x55b69309d6a8 <unknown>
from #14 0x55b69309d836 <unknown>
from #15 0x55b6930b8d13 <unknown>
... 7 levels...
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:102:in `create_session'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/bridge.rb:56:in `handshake'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/chrome/driver.rb:43:in `initialize'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:46:in `new'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/common/driver.rb:46:in `for'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver.rb:88:in `for'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/capybara-2.7.1/lib/capybara/selenium/driver.rb:14:in `browser'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/capybara-2.7.1/lib/capybara/selenium/driver.rb:46:in `visit'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/capybara-2.7.1/lib/capybara/session.rb:233:in `visit'
from (irb):21
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/railties-3.2.22.5/lib/rails/commands/console.rb:47:in `start'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/railties-3.2.22.5/lib/rails/commands/console.rb:8:in `start'
from /var/www/apps/einstein_staging/shared/bundle/ruby/2.3.0/gems/railties-3.2.22.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:21:in `require'
from script/rails:21:in `<main>'
Related
I tried to run a simple google look up code in selenium and ran it on EC2 instance(Amazon Linux). I am getting an error launching Firefox and cannot understand what the error means.
Ruby version - ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
selenium-webdriver version - 3.142.3
require 'selenium-webdriver'
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
driver = Selenium::WebDriver.for(:firefox, options: options)
driver.get "http://google.com"
puts "Page title is #{driver.title}"
driver.quit
When running ruby test.rb
Traceback (most recent call last):
8: from test.rb:4:in `<main>'
7: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver.rb:88:in `for'
6: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:54:in `for'
5: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
4: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
3: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/marionette/driver.rb:38:in `initialize'
2: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:299:in `service_url'
1: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:45:in `firefox'
/usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/binary.rb:134:in `path': can't modify frozen String (FrozenError)
Need some help here.
You'll get that error if Firefox isn't installed, or isn't accessible on your path.
Reinstall if you already have it.
Also, as of selenium-webdriver 3.142.3, you can check the current Firefox binary path using this:
Selenium::WebDriver::Firefox::Binary.path
This would throw this same FrozenError if no binary is found, and return the binary path if a Firefox binary has been found somewhere.
Also worth mentioning that an issue has been opened in the selenium-webdriver repo to make the error message more explanatory, if you're interested.
I'm running Ubuntu 16.04 and I'm trying to run a headless Chrome browser in ruby with chromedriver.
I've installed chromedriver on Ubuntu using these instructions and then I run this via the ruby irb console:
require 'selenium-webdriver'
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
#driver = Selenium::WebDriver.for(:chrome, options: options)
Traceback (most recent call last):
10: from /home/weefee/.rvm/rubies/ruby-2.5.1/bin/irb:11:in `<main>'
9: from (irb):5
8: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver.rb:86:in `for'
7: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb:44:in `for'
6: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/driver.rb:44:in `new'
5: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/chrome/driver.rb:44:in `initialize'
4: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:69:in `start'
3: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/socket_lock.rb:39:in `locked'
2: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:72:in `block in start'
1: from /home/weefee/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/common/service.rb:142:in `connect_until_stable'
Selenium::WebDriver::Error::WebDriverError (unable to connect to chromedriver 127.0.1.1:9515)
Any idea on how to fix it? A few notes:
Some people seem to encounter issues with rbenv and the shim that it sets up. I'm not using rbenv at all, so that's irrelevant here.
The above works when I try it on my OSx laptop. Of course there I can easily install chromedriver with brew install chromedriver and it just seems to work
Alternatively, I uninstalled chromedriver and re-installed it using the chromedriver-helper gem. Still the same result.
I've been tearing my hair out for a while on this - any help would be appreciated. Thanks!
UPDATE
I dug deeper into the source of the selenium-webdriver gem to see exactly what it was doing when trying to connect to the chromedriver process.
I was able to replicate the following in my ruby console on the server using the same commands the selenium-webdriver gem uses:
#
# Start the Chromedriver Process
#
require 'childprocess'
process = ChildProcess.build(*["/usr/local/bin/chromedriver", "--port=9515"])
process.leader = true
process.alive? #=> false
process.start
process.alive? #=> true
#
# Create a Socket connection to 127.0.0.1:9515
#
require 'socket'
require 'selenium-webdriver'
host = Selenium::WebDriver::Platform.localhost #=> "127.0.1.1"
port = Integer(Selenium::WebDriver::Chrome::Service::DEFAULT_PORT) #=> 9515
timeout = 5
# Create and connect to socket
addr = Socket.getaddrinfo(host, port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(port, addr[0][3])
# First need to rescue the writable error and then connect again
# to get the actual error. No idea why but even the official
# rubydocs use this pattern: https://apidock.com/ruby/Socket/connect_nonblock
begin
sock.connect_nonblock(sockaddr)
rescue IO::WaitWritable
IO.select(nil, [sock], nil, 5)
sock.connect_nonblock(sockaddr)
end
#=> Errno::ECONNREFUSED (Connection refused - connect(2) for 127.0.1.1:9515)
So it seems the core error is that the socket refuses to connect on that (local) address and port, even though chromedriver is very much running on that port.
I don't know much about sockets at all - is this a common error?
Thanks!
I have tried it on the Ubuntu 16.04 (updated) and ruby which comes with the system ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu].
From what I guess is that you are using wrong, old (in the guide there is version 2.26 which will not work with current chrome), chromedriver, which is not compatible with the current stable chrome.
The current stable chrome is Unpacking google-chrome-stable (71.0.3578.98-1) ... and so you need to get chromedriver as close as possible to the chrome version.
To get complete list of chromedrivers' versions click here.
In my case that would be a 71.0.3578.80 version:
wget -N http://chromedriver.storage.googleapis.com/71.0.3578.80/chromedriver_linux64.zip
You can then continue as shown at the instructions.
Then you will get working selenium-webdriver:
irb
irb(main):001:0> require 'selenium-webdriver'
=> true
irb(main):003:0> options = Selenium::WebDriver::Chrome::Options.new
=> #<Selenium::WebDriver::Chrome::Options:0x00000002ee6db0 #args=#<Set: {}>, #binary=nil, #prefs={}, #extensions=[], #options={}, #emulation={}, #encoded_extensions=[]>
irb(main):004:0> options.add_argument('--headless')
=> #<Set: {"--headless"}>
irb(main):005:0> #driver = Selenium::WebDriver.for(:chrome, options: options)
=> #<Selenium::WebDriver::Chrome::Driver:0x..f95c429ee62a3a152 browser=:chrome>
Note: If you have issues installing ffi install libffi-dev via apt-get.
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --only-upgrade install google-chrome-stable
This will keep your version up to date and available. I have had this solve similar problems that were encountered during CI testing. You should be able to setup your #driver afterwards.
from this line:
Selenium::WebDriver::Error::WebDriverError (unable to connect to chromedriver 127.0.1.1:9515)
it suggests you are trying to connect to 127.0.1.1, while your localhost should be 127.0.0.1, could you check your configuration?
All the provided solutions were great recommendations, but ultimately tukan's answer led me down the path of carefully checking versions.
The setup I had didn't work on Ubuntu 14.04, which is about 5 years old at the time of this writing. I re-built the whole thing on an Ubuntu 16.04 machine and it worked perfectly.
I don't know what causes the error, but it seems to be something at the operating system level.
I'm using a bot that used to work perfectly. Since yesterday, I cannot connect with this bot to the website. Manually I can with not any issue. To solve it I tried to use a VPN to change my IP in case the website would block my IP. Maybe it comes from my firewall ?
Configuration :
Windows 10 64bits
Ruby23-x64 (I use to have Ruby24 but downgrade to try to solve the issue)
In the following log it seems to be on RubyGems 2.3.0 but when I do "gem update --system" I have another result so not sure which version it is :
Bundler 1.16.0 installed
RubyGems 2.7.4 installed
Log :
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/abstract_response.rb:223:in `exception_with_response': 503 Service Unavailable (RestClient::ServiceUnavailable)
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/abstract_response.rb:103:in `return!'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:809:in `process_result'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:725:in `block in transmit'
from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:853:in `start'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:715:in `transmit'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:145:in `execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:52:in `execute'
from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient.rb:67:in `get'
from yobit_bot.rb:57:in `call_api'
from yobit_bot.rb:85:in `get_market_summary'
from yobit_bot.rb:171:in `buy_sell_bot'
from yobit_bot.rb:228:in `<main>'
I found the solution by replacing the url I try to connect "https://yobit.net/" by "https://www.yobit.net/"
I am trying to get cucumber tests to run on our headless centOS box.
I have installed Xvfb, firefox, and my test suite, which functions on our non-headless(headed?) machines.
Versions
CentOS: 6.2
firefox: 23.0.1
headless: 1.0.1
selenium-webdriver: 2.35.0
watir-webdriver: 0.6.4
ruby: 1.9.3
In irb:
1.9.3-p448 :001 > require 'watir-webdriver'
=> true
1.9.3-p448 :002 > require 'headless'
=> true
1.9.3-p448 :004 > headless = Headless.new
=> #<Headless:0x000000025e0860 #display=99, #autopick_display=true, #reuse_display=true, #dimensions="1280x1024x24", #video_capture_options={}, #destroy_at_exit=true>
1.9.3-p448 :005 > headless.start
=> #<Proc:0x000000025e5180#/usr/local/rvm/gems/ruby-1.9.3-p448/gems/headless-1.0.1/lib/headless.rb:175>
1.9.3-p448 :006 > b = Watir::Browser.new(:firefox)
Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.35.0/lib/selenium/webdriver.rb:67:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/watir-webdriver/browser.rb:46:in `initialize'
from (irb):6:in `new'
from (irb):6
from /usr/local/rvm/rubies/ruby-1.9.3-p448/bin/irb:13:in `<main>'
I have the same issue when trying to run the tests (this is just easier to reproduce).
I checked out the other questions here, but I am already using the latest version. According to the changelog they support firefox 23. Does anyone have any ideas? Thanks in advance!
UPDATE 8/28/2013 0900:
I was getting this error when I tried to run Xvfb.
[dix] Could not init font path element catalogue:/etc/X11/fontpath.d, removing from list!
[dix] Could not init font path element built-ins, removing from list!
I fixed it by using
yum -y install libXfont
But I am still getting the same error.
UPDATE 8/28/2013 0930:
As per TDHM's suggestion, I downgraded firefox to 17.0.8 by running
yum downgrade firefox
But I am still getting the same error.
A co-worker of mine managed to fix the issue.
Run this line of code:
$ dbus-uuidgen > /var/lib/dbus/machine-id
And the problem is fixed. This is the source for the fix
I'm not sure, but see if downgrading Firefox version works. Because many times latest version of Selenium has problems with latest browser versions.
There's a method in my Rails app (intended to be triggered via Rake task) that shells out and runs a PhantomJS process:
bin/proximo bin/phantomjs vendor/assets/javascripts/yslow.js http://www.example.com
The phantomjs executable is 1.8.1 or Linux (x86-64). yslow.js is YSlow for PhantomJS 3.1.1.
The process is run through Heroku's Proximo add-on, because the website I'm running this against (example.com above) will show anti-DOS protection page to any IP that's not whitelisted.
The problem I'm experiencing is that this command simply hangs, returning no output. If I run the same command without executing the bin/proximo wrapper script, it works, but of course I get output for the wrong page, due to the IP restriction mentioned above.
Here is a stack trace from running this directly in a Rails console on Heroku:
irb(main):023:0> `bin/proximo bin/phantomjs vendor/assets/javascripts/yslow.js http://www.example.com`
^CIRB::Abort: abort then interrupt!
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/core_ext/kernel/agnostics.rb:7:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
from (irb):23
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any ideas what's causing the hang?
Edit: My coworker helped me discover that it's actually PhantomJS that's hanging, not the proxy. I'll look for another way of vendoring PhantomJS, unless someone else has another suggestion.
Edit 2: I installed PhantomJS with the Heroku buildpack, and the same thing happens. I also notice that if I connect to a Bash shell on Heroku and run the phantomjs console, I can't enter commands in it because the enter key does nothing. Not sure if that's related...