我对 Selenium 非常陌生,突然间无缘无故地出现一个错误阻止我运行任何 Selenium 测试。
这是我运行 Python 脚本时遇到的错误:
2018-05-14 12:07:52,766 [INFO ] Getting Selenium setup here.
Traceback (most recent call last):
File "test.py", line 308, in <module>
webcrawler.crawl()
File "test.py", line 177, in crawl
self.web_crawl.setup()
File "/test/src/webcrawlers/utils/webcrawl_lib.py", line 83, in setup
self.browser = webdriver.Firefox(firefox_profile=profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 162, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
现在我通常可以调试这些问题。然而,geckodriver.log 并没有给我太多的帮助:
1526299672891 geckodriver INFO geckodriver 0.20.1
1526299672895 geckodriver INFO Listening on 127.0.0.1:48641
1526299673899 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.YNIc2l05QiIr"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/test which is owned by test.)
环境:
- Geckodriver:0.20.1
- Selenium :3.12.0 Python:2.7。我也尝试过使用 3
- 火狐:60.0
我什至尝试改用 Chrome,但设置会挂起并给出一个独特的错误。
附注是,这是在 Amazon AWS 上,我不是该帐户的管理员。也许这方面发生了一些变化。
最佳答案
我在 geckodriver 0.21.1、Selenium 3.12.0 和 Python 3.5.2 上也遇到了同样的问题。它对我在 Ubuntu 17.04 上使用 sudo apt-get purge firefox, firefox-dev
删除 Firefox 和 (firefox-dev
) 有用,然后我手动安装 Firefox 版本 50.0 :
wget http://ftp.mozilla.org/pub/firefox/releases/50.0/linux-$(uname -m)/en-US/firefox-50.0.tar.bz2
tar -xjf firefox-50.0.tar.bz2
sudo mv firefox /opt/
sudo mv /usr/bin/firefox /usr/bin/firefox_old
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
完成这些步骤后,它也可以在 root 下使用。
关于Selenium - 不支持在常规用户 session 中以 root 身份运行 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50330246/