我尝试在VPS上运行硒以在python中运行测试。我有一些python代码
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.log.level = 'trace'
selenium = Firefox(firefox_options=options)
我得到一个错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/testy/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/home/testy/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/testy/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/testy/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/testy/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
Firefox启动,但是,在python引发异常之后,它才可用,并且它对此无效。
geckodriver.log说
1540423460336 geckodriver INFO geckodriver 0.21.0
1540423460465 geckodriver INFO Listening on 127.0.0.1:34241
1540423461245 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.MmPzTonVHFIu"
1540423461272 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:36731
1540423475244 Marionette DEBUG Received observer notification "profile-after-change"
1540423476412 Marionette DEBUG Received observer notification "command-line-startup"
1540423476412 Marionette INFO Enabled via --marionette
1540423514528 Marionette DEBUG Received observer notification "sessionstore-windows-restored"
1540423521297 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}
1540423524134 addons.xpi WARN Exception running bootstrap method shutdown on activity-stream@mozilla.org: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsINavHistoryService.removeObserver]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://activity-stream/lib/PlacesFeed.jsm :: removeObservers :: line 220" data: no] Stack trace: removeObservers()@resource://activity-stream/lib/PlacesFeed.jsm:220 < onAction()@resource://activity-stream/lib/PlacesFeed.jsm:257 < _middleware/</<()@resource://activity-stream/lib/Store.jsm:51 < Store/this[method]()@resource://activity-stream/lib/Store.jsm:30 < uninit()@resource://activity-stream/lib/Store.jsm:153 < uninit()@resource://activity-stream/lib/ActivityStream.jsm:274 < uninit()@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///usr/lib/firefox/browser/features/activity-stream@mozilla.org.xpi!/bootstrap.js:80 < shutdown()@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///usr/lib/firefox/browser/features/activity-stream@mozilla.org.xpi!/bootstrap.js:196 < callBootstrapMethod()@resource://gre/modules/addons/XPIProvider.jsm:4419 < observe()@resource://gre/modules/addons/XPIProvider.jsm:2279
Promise rejected after context unloaded: Message manager disconnected
1540423541320 Marionette DEBUG Setting recommended pref apz.content_response_timeout to 60000
1540423541388 Marionette DEBUG Setting recommended pref browser.download.panel.shown to true
1540423541390 Marionette DEBUG Setting recommended pref browser.EULA.override to true
1540423541390 Marionette DEBUG Setting recommended pref browser.newtabpage.enabled to false
1540423541598 Marionette DEBUG Setting recommended pref browser.newtabpage.introShown to true
1540423541598 Marionette DEBUG Setting recommended pref browser.offline to false
1540423541598 Marionette DEBUG Setting recommended pref browser.pagethumbnails.capturing_disabled to true
1540423541630 Marionette DEBUG Setting recommended pref browser.search.update to false
1540423541688 Marionette DEBUG Setting recommended pref toolkit.cosmeticAnimations.enabled to false
1540423541822 Marionette DEBUG Setting recommended pref browser.tabs.disableBackgroundZombification to false
1540423541822 Marionette DEBUG Setting recommended pref browser.tabs.warnOnCloseOtherTabs to false
1540423541822 Marionette DEBUG Setting recommended pref browser.tabs.warnOnOpen to false
1540423541822 Marionette DEBUG Setting recommended pref browser.usedOnWindows10.introURL to
1540423541824 Marionette DEBUG Setting recommended pref browser.urlbar.suggest.searches to false
1540423541960 Marionette DEBUG Setting recommended pref browser.urlbar.userMadeSearchSuggestionsChoice to true
1540423542166 Marionette DEBUG Setting recommended pref datareporting.policy.dataSubmissionPolicyAccepted to false
1540423542166 Marionette DEBUG Setting recommended pref dom.disable_open_during_load to false
1540423542166 Marionette DEBUG Setting recommended pref dom.file.createInChild to true
1540423542168 Marionette DEBUG Setting recommended pref dom.max_chrome_script_run_time to 0
1540423542208 Marionette DEBUG Setting recommended pref dom.max_script_run_time to 0
1540423542320 Marionette DEBUG Setting recommended pref extensions.getAddons.cache.enabled to false
1540423542320 Marionette DEBUG Setting recommended pref extensions.webservice.discoverURL to http://%(server)s/dummy/discoveryURL
1540423542320 Marionette DEBUG Setting recommended pref network.http.prompt-temp-redirect to false
1540423542320 Marionette DEBUG Setting recommended pref network.http.speculative-parallel-limit to 0
1540423542320 Marionette DEBUG Setting recommended pref security.fileuri.strict_origin_policy to false
1540423542322 Marionette DEBUG Setting recommended pref security.notification_enable_delay to 0
1540423542322 Marionette DEBUG Setting recommended pref signon.autofillForms to false
1540423542322 Marionette DEBUG Setting recommended pref signon.rememberSignons to false
1540423542372 Marionette DEBUG New connections are accepted
1540423542372 Marionette INFO Listening on port 36731
console.error:
Message: Error: SessionFile is closed
Stack:
write@resource:///modules/sessionstore/SessionFile.jsm:385:29
write@resource:///modules/sessionstore/SessionFile.jsm:73:12
_writeState@resource:///modules/sessionstore/SessionSaver.jsm:363:12
_saveState@resource:///modules/sessionstore/SessionSaver.jsm:301:12
_saveStateAsync@resource:///modules/sessionstore/SessionSaver.jsm:347:5
saveStateAsyncWhenIdle@resource:///modules/sessionstore/SessionSaver.jsm:198:9
1540423545096 addons.productaddons WARN Failed downloading XML, status: 0, reason: error
1540423545192 addons.productaddons WARN Failed downloading via XHR, status: 0, reason: error
1540423546620 Marionette DEBUG Received observer notification "xpcom-shutdown"
1540423546622 Marionette DEBUG Resetting recommended pref apz.content_response_timeout
1540423546622 Marionette DEBUG Resetting recommended pref browser.download.panel.shown
1540423546622 Marionette DEBUG Resetting recommended pref browser.EULA.override
1540423546622 Marionette DEBUG Resetting recommended pref browser.newtabpage.enabled
1540423546724 Marionette DEBUG Resetting recommended pref browser.newtabpage.introShown
1540423546724 Marionette DEBUG Resetting recommended pref browser.offline
1540423546724 Marionette DEBUG Resetting recommended pref browser.pagethumbnails.capturing_disabled
1540423546724 Marionette DEBUG Resetting recommended pref browser.search.update
1540423546724 Marionette DEBUG Resetting recommended pref toolkit.cosmeticAnimations.enabled
1540423546726 Marionette DEBUG Resetting recommended pref browser.tabs.disableBackgroundZombification
1540423546726 Marionette DEBUG Resetting recommended pref browser.tabs.warnOnCloseOtherTabs
1540423546726 Marionette DEBUG Resetting recommended pref browser.tabs.warnOnOpen
1540423546726 Marionette DEBUG Resetting recommended pref browser.usedOnWindows10.introURL
1540423546726 Marionette DEBUG Resetting recommended pref browser.urlbar.suggest.searches
1540423546866 Marionette DEBUG Resetting recommended pref browser.urlbar.userMadeSearchSuggestionsChoice
1540423547056 Marionette DEBUG Resetting recommended pref datareporting.policy.dataSubmissionPolicyAccepted
1540423547056 Marionette DEBUG Resetting recommended pref dom.disable_open_during_load
1540423547056 Marionette DEBUG Resetting recommended pref dom.file.createInChild
1540423547056 Marionette DEBUG Resetting recommended pref dom.max_chrome_script_run_time
1540423547056 Marionette DEBUG Resetting recommended pref dom.max_script_run_time
1540423547172 Marionette DEBUG Resetting recommended pref extensions.getAddons.cache.enabled
1540423547172 Marionette DEBUG Resetting recommended pref extensions.webservice.discoverURL
1540423547172 Marionette DEBUG Resetting recommended pref network.http.prompt-temp-redirect
1540423547172 Marionette DEBUG Resetting recommended pref network.http.speculative-parallel-limit
1540423547172 Marionette DEBUG Resetting recommended pref security.fileuri.strict_origin_policy
1540423547172 Marionette DEBUG Resetting recommended pref security.notification_enable_delay
1540423547172 Marionette DEBUG Resetting recommended pref signon.autofillForms
1540423547172 Marionette DEBUG Resetting recommended pref signon.rememberSignons
1540423547172 Marionette DEBUG New connections will no longer be accepted
您能告诉我,您知道其他类似情况的调试方法吗? 我在用 python 2.7
硒3.14.1
firefox 59.0.2(与ff62产生相同的错误)
geckodriver 0.21(0.23会产生相同的错误)
答案 0 :(得分:1)
根据 Selenium Python Client v3.14.0 的selenium.webdriver.firefox.options的文档,您需要使用:
class selenium.webdriver.firefox.options.Log
示例代码块:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.options import Log
log = Log()
log.level = "TRACE"
options = Options()
options.add_argument(log.level)
browser = webdriver.Firefox(firefox_options=options,executable_path="C:\\path\\to\\geckodriver.exe")
browser.get('http://google.com/')