selenium - Selenium - 不支持在常规用户会话中以 root 身份运行 Firefox
问题描述
我对 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.)
环境:
- 壁虎司机:0.20.1
- 硒:3.12.0
- 蟒蛇:2.7。我也尝试使用 3
- 火狐:60.0
我什至尝试切换到使用 Chrome,但设置会挂起并给出一个独特的错误。
附带说明,这是在 Amazon AWS 上,我不是该帐户的管理员。也许在那方面发生了一些变化。
解决方案
I had the same problem with geckodriver 0.21.1, Selenium 3.12.0, and Python 3.5.2. It worked for me on Ubuntu 17.04 to remove Firefox and (firefox-dev
) with sudo apt-get purge firefox, firefox-dev
and then I install Firefox version 50.0 manually with:
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
After those steps it also worked with root.
推荐阅读
- python - 访问上一个堆栈帧中可用的局部变量
- python - Airflow 任务的内存、CPU 和 IO
- python-3.x - PCA 或线性判别分析?QoS中的分类问题
- android - TextField 获得焦点时如何滚动到 SingleChildScrollView 的底部?
- c++ - 使用 cmake 编译时未定义的引用
- ruby - 在“initialize”方法中访问实例变量
- vue.js - VueJS 复杂的 v-if
- c# - 是 bool 布尔型;与 bool booly = false 相同;什么时候宣布?
- excel - 仅当 DOB 存在时才计算年龄
- database - 基于变量名称的模式匹配以在 Postgres 查询中选择变量?