在docker中第二次运行时如何修复硒?

时间:2019-02-28 13:38:31

标签: python selenium docker

我正在docker中运行一个shell脚本,该脚本打开浏览器,进行某些Web抓取,并使用`webdriver.quit()关闭。第一次刮擦效果很好,但是在第二次运行时,它无法制作webdriver实例,并给我一个错误。

browser = webdriver.Firefox(options=options, executable_path="./geckodriver", firefox_profile=fp)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

我不确定该怎么做,我已使用firefox 65和geckodriver 24确保我的geckodriver和friefox版本正确。

我回去尝试在docker容器内交互运行代码,并得到failed to decode from marionette

>>> browser = start_browser(url, headless=True)
path: /tmp/
>>> log_in(username, password, browser, userxpath=None, passxpath=None, loginxpath=None)
>>> properties = (By.XPATH, "//input[@id='ctl00_content_BookingStatus1_cmdFavorite']")
>>> favourite_dropdown = WebDriverWait(browser, 10).until(
...     EC.element_to_be_clickable((properties))
... )
>>> time.sleep(1)
>>> favourite_dropdown.click()
>>> time.sleep(1)
>>> favourite = browser.find_element_by_link_text(fav_text)
>>> favourite.click()
>>> selectfav = browser.find_element_by_xpath("//a[@class='favoriteCurrent']").text
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //a[@class='favoriteCurrent']

>>> favourite.click()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette

0 个答案:

没有答案