WebDriverException:消息:退出

时间:2017-08-04 11:17:13

标签: python linux selenium firefox geckodriver

我有以下设置:

Linux
Python 2.7.6
Mozilla Firefox 52.2.0
geckodriver 0.18.0
selenium Version: 3.4.3

我正在运行一个简单的python脚本:

import time
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)  # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/tmp')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'image/png')

driver = webdriver.Firefox(firefox_profile=profile)
driver.get("file:////home/temp-plot.html")
export_button = driver.find_element_by_xpath("//a[@data-title='Download plot as a png']")
export_button.click()
time.sleep(10)
driver.quit()

但是当我到达driver.quit()时,我遇到以下错误:

Traceback (most recent call last):
  File "conversor.py", line 17, in <module>
    driver.quit()
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 181, in quit
    RemoteWebDriver.quit(self)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 551, in quit
    self.execute(Command.QUIT)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: quit

如果我运行driver.close()而不是driver.quit(),我没有错误消息,但另一方面,我发现geckodriver进程没有被杀死,这对我来说是一个问题。

root     14572     1  0 11:56 pts/0    00:00:00 geckodriver --port 39203

如何修复此异常错误?或者你建议我做什么?

由于

2 个答案:

答案 0 :(得分:1)

这对我很有用:

driver.close()

而不是:

driver.quit()

我在python3,selenium 3.4.3

答案 1 :(得分:-1)

我不知道为什么geckodriver这样做,但异常捕获在我们的项目上完成了工作:

<xsl:value-of select="(speaks/@lang | speaks/@nolang)[1]" />        

浏览器和gecko驱动程序已关闭,并且不会报告任何无用的错误。