报错:
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1
坑点:这通过查看geckodriver.log可以发现:
1565086641745 geckodriver INFO geckodriver 0.19.0
1565086641748 geckodriver INFO Listening on 127.0.0.1:56020
1565086641834 mozrunner::runner INFO Running command: "/usr/lib64/firefox/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.3LBcykrEU73V"
Running Firefox as root in a regular user's session is not supported. ($XDG_RUNTIME_DIR is /run/user/1000 which is owned by admin.)
上面错误,不支持在普通用户的会话中以root身份运行Firefox。解决方法:切换到其他用户执行即可。
测试代码
import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
time.sleep(3)
driver.quit()
在远程服务器直接运行没问题,但是在win10 pycharm进行远程运行时报错:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.