Selenium Chromedriver无法启动

时间:2019-10-29 12:33:27

标签: python django selenium

我正在尝试使用带有chrome驱动程序的硒测试我的代码。但是我总是在终端中收到此错误消息。

======================================================================
ERROR: test_input_status (myweb.tests.StorySixFunctionalTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fredypasaud/Documents/PPW/story_six/myweb/tests.py", line 58, in setUp
    self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
  File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /snap/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

然后我将chromedriver与项目的manage.py放在同一目录中。这是我test.py中的一些代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

class StorySixFunctionalTest(TestCase):

    def setUp(self):
        chrome_options = Options()
        self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
        chrome_options.add_argument('--dns-prefetch-disable')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('disable-gpu')
        chrome_options.addArguments("--disable-extensions");
        chrome_options.addArguments("--disable-dev-shm-usage");
        super(StorySixFunctionalTest, self).setUp()

    def tearDown(self):
        self.selenium.quit()
        super(StorySixFunctionalTest, self).tearDown()

    def test_input_status(self):
        selenium = self.selenium
        selenium.get('http://127.0.0.1:8000/index/')

        status = selenium.find_element_by_id('id_status')
        submit = selenium.find_element_by_id('submit')

        status.send_keys("Coba Coba")
        submit.send_keys(Keys.RETURN)

更新:

我正在尝试通过显示chromedriver日志来调试程序,而我却收到此错误(这很奇怪,因为我安装了canbera模块)

Gtk-Message: 14:40:58.177: Failed to load module "canberra-gtk-module"
Gtk-Message: 14:40:58.196: Failed to load module "canberra-gtk-module"

0 个答案:

没有答案