Selenium Firefox WebDriver在无头Ubuntu上不起作用

时间:2019-07-19 16:23:54

标签: ruby selenium ubuntu

我在Ubuntu 16.04上以suggested的身份安装了firefoxxvfb。我还安装了geckodriver 0.24.0。我那里没有监视器,它只是一台服务器,带有SSH终端。然后,我正在尝试:

require 'selenium-webdriver'
Selenium::WebDriver.logger.level = :debug
options = Selenium::WebDriver::Firefox::Options.new
options.headless!
options.log_level = :trace
driver = Selenium::WebDriver.for(:firefox, options: options)
driver.get('http://stackoverflow.com/')
puts driver.title
driver.quit

此代码可在我的Mac上完美运行。但是,在Ununtu上,它卡在pageshow DOM事件之前。这就是我得到的:

$ ruby x.rb
2019-07-19 18:17:55 DEBUG Selenium Executing Process ["/usr/local/bin/geckodriver", "--port=4444", "--binary=/usr/bin/firefox"]
2019-07-19 18:17:55 DEBUG Selenium polling for socket on ["127.0.0.1", 4444]
2019-07-19 18:17:55 INFO Selenium Skipping handshake as we know it is W3C.
2019-07-19 18:17:55 INFO Selenium -> POST session
2019-07-19 18:17:55 INFO Selenium    >>> http://127.0.0.1:4444/session | {"desiredCapabilities":{"browserName":"firefox","version":"","platform":"ANY","javascriptEnabled":false,"cssSelectorsEnabled":false,"takesScreenshot":false,"nativeEvents":false,"rotatable":false,"marionette":true,"timeouts":{},"moz:firefoxOptions":{"args":["-headless"],"log":{"level":"trace"}}},"capabilities":{"firstMatch":[{"browserName":"firefox","timeouts":{},"moz:firefoxOptions":{"args":["-headless"],"log":{"level":"trace"}}}]}}
2019-07-19 18:17:55 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/3.142.3 (ruby linux)", "Content-Length"=>"436"}
1563553075310 mozrunner::runner INFO  Running command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.tvxJGgq0FR8a"
1563553075310 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:37539
*** You are running in headless mode.
1563553075784 addons.webextension.screenshots@mozilla.org WARN  Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1563553075784 addons.webextension.screenshots@mozilla.org WARN  Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1563553075785 addons.webextension.screenshots@mozilla.org WARN  Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1563553075785 addons.webextension.screenshots@mozilla.org WARN  Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1563553075916 Marionette  TRACE Received observer notification profile-after-change
1563553075947 Marionette  TRACE Received observer notification command-line-startup
1563553075947 Marionette  TRACE Received observer notification nsPref:changed
1563553075948 Marionette  DEBUG Init aborted (running=false, enabled=true, finalUIStartup=false)
1563553076070 Marionette  TRACE Received observer notification toplevel-window-ready
1563553077674 Marionette  TRACE Received observer notification marionette-startup-requested
1563553077674 Marionette  TRACE Waiting until startup recorder finished recording startup scripts...
1563553077690 Marionette  TRACE All scripts recorded.
1563553077691 Marionette  DEBUG Setting recommended pref apz.content_response_timeout to 60000
1563553077692 Marionette  DEBUG Setting recommended pref browser.contentblocking.introCount to 99
1563553077692 Marionette  DEBUG Setting recommended pref browser.download.panel.shown to true
1563553077693 Marionette  DEBUG Setting recommended pref browser.newtabpage.enabled to false
1563553077695 Marionette  DEBUG Setting recommended pref browser.pagethumbnails.capturing_disabled to true
1563553077696 Marionette  DEBUG Setting recommended pref browser.search.update to false
1563553077696 Marionette  DEBUG Setting recommended pref browser.tabs.disableBackgroundZombification to false
1563553077696 Marionette  DEBUG Setting recommended pref browser.tabs.remote.separatePrivilegedContentProcess to false
1563553077696 Marionette  DEBUG Setting recommended pref browser.tabs.unloadOnLowMemory to false
1563553077696 Marionette  DEBUG Setting recommended pref browser.tabs.warnOnCloseOtherTabs to false
1563553077697 Marionette  DEBUG Setting recommended pref browser.tabs.warnOnOpen to false
1563553077697 Marionette  DEBUG Setting recommended pref browser.usedOnWindows10.introURL to
1563553077697 Marionette  DEBUG Setting recommended pref browser.urlbar.suggest.searches to false
1563553077698 Marionette  DEBUG Setting recommended pref datareporting.policy.dataSubmissionPolicyAccepted to false
1563553077698 Marionette  DEBUG Setting recommended pref dom.disable_beforeunload to true
1563553077698 Marionette  DEBUG Setting recommended pref dom.disable_open_during_load to false
1563553077698 Marionette  DEBUG Setting recommended pref dom.file.createInChild to true
1563553077699 Marionette  DEBUG Setting recommended pref dom.max_chrome_script_run_time to 0
1563553077699 Marionette  DEBUG Setting recommended pref dom.max_script_run_time to 0
1563553077700 Marionette  DEBUG Setting recommended pref dom.push.connection.enabled to false
1563553077700 Marionette  DEBUG Setting recommended pref extensions.getAddons.cache.enabled to false
1563553077700 Marionette  DEBUG Setting recommended pref extensions.webservice.discoverURL to http://%(server)s/dummy/discoveryURL
1563553077700 Marionette  DEBUG Setting recommended pref network.http.prompt-temp-redirect to false
1563553077700 Marionette  DEBUG Setting recommended pref network.http.speculative-parallel-limit to 0
1563553077700 Marionette  DEBUG Setting recommended pref privacy.trackingprotection.enabled to false
1563553077701 Marionette  DEBUG Setting recommended pref security.certerrors.mitm.priming.enabled to false
1563553077701 Marionette  DEBUG Setting recommended pref security.fileuri.strict_origin_policy to false
1563553077701 Marionette  DEBUG Setting recommended pref security.notification_enable_delay to 0
1563553077701 Marionette  DEBUG Setting recommended pref signon.autofillForms to false
1563553077702 Marionette  DEBUG Setting recommended pref signon.rememberSignons to false
1563553077702 Marionette  DEBUG Setting recommended pref toolkit.cosmeticAnimations.enabled to false
1563553077792 Marionette  INFO  Listening on port 37539
1563553077792 Marionette  DEBUG Remote service is active
1563553077815 geckodriver::marionette DEBUG Connection established on 127.0.0.1:37539. Waiting for Marionette handshake
1563553077832 Marionette  DEBUG Accepted connection 0 from 127.0.0.1:42584
1563553077841 geckodriver::marionette DEBUG Connected to Marionette
1563553077845 Marionette  DEBUG 0 -> [0,1,"WebDriver:NewSession",{"browserName":"firefox","timeouts":{}}]
1563553077884 Marionette  TRACE [4294967297] Frame script loaded
1563553077885 Marionette  TRACE [4294967297] Frame script registered
1563553077894 Marionette  DEBUG 0 <- [1,1,null,{"sessionId":"e938d196-7ac8-4bb8-a4c1-60de070e3713","capabilities":{"browserName":"firefox","browserVersion":"69.0" ... ozprofile.tvxJGgq0FR8a","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true}}]
1563553077902 webdriver::server DEBUG <- 200 OK {"value":{"sessionId":"e938d196-7ac8-4bb8-a4c1-60de070e3713","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"69.0","moz:accessibilityChecks":false,"moz:buildID":"20190718232037","moz:geckodriverVersion":"0.24.0","moz:headless":true,"moz:processID":5016,"moz:profile":"/tmp/rust_mozprofile.tvxJGgq0FR8a","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"linux","platformVersion":"4.4.0-78-generic","rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}
2019-07-19 18:17:57 INFO Selenium <- {"value":{"sessionId":"e938d196-7ac8-4bb8-a4c1-60de070e3713","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"69.0","moz:accessibilityChecks":false,"moz:buildID":"20190718232037","moz:geckodriverVersion":"0.24.0","moz:headless":true,"moz:processID":5016,"moz:profile":"/tmp/rust_mozprofile.tvxJGgq0FR8a","moz:shutdownTimeout":60000,"moz:useNonSpecCompliantPointerOrigin":false,"moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"linux","platformVersion":"4.4.0-78-generic","rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}
2019-07-19 18:17:57 INFO Selenium Detected W3C dialect.
2019-07-19 18:17:57 INFO Selenium -> POST session/e938d196-7ac8-4bb8-a4c1-60de070e3713/url
2019-07-19 18:17:57 INFO Selenium    >>> http://127.0.0.1:4444/session/e938d196-7ac8-4bb8-a4c1-60de070e3713/url | {"url":"http://stackoverflow.com/"}
2019-07-19 18:17:57 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/3.142.3 (ruby linux)", "Content-Length"=>"35"}
1563553077904 webdriver::server DEBUG -> POST /session/e938d196-7ac8-4bb8-a4c1-60de070e3713/url {"url":"http://stackoverflow.com/"}
1563553077908 Marionette  DEBUG 0 -> [0,2,"WebDriver:Navigate",{"url":"http://stackoverflow.com/"}]
1563553077923 Marionette  TRACE [4294967297] Received DOM event beforeunload for about:blank
1563553082588 Marionette  TRACE [4294967297] Received DOM event pagehide for about:blank
1563553083837 Marionette  TRACE [4294967297] Received DOM event DOMContentLoaded for https://stackoverflow.com/
Traceback (most recent call last):
  17: from post.rb:8:in `<main>'
  16: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:130:in `get'
  15: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
  14: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
  13: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
  12: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
  11: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
  10: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
   9: from /home/yegor/.rvm/gems/ruby-2.5.1/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
   8: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:1464:in `request'
   7: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:1491:in `transport_request'
   6: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:1491:in `catch'
   5: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:1494:in `block in transport_request'
   4: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http/response.rb:29:in `read_new'
   3: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http/response.rb:40:in `read_status_line'
   2: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/protocol.rb:167:in `readline'
   1: from /home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/protocol.rb:157:in `readuntil'
/home/yegor/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/protocol.rb:181:in `rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)

0 个答案:

没有答案