我想运行chromedriver_autoinstaller
。我在这里举个例子:https://pypi.org/project/chromedriver-autoinstaller/
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
但我有一个错误:
Traceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 9, in <module>
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/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: DevToolsActivePort file doesn't exist
这是什么意思?这个包裹还在用吗?
此错误消息。。。
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
意味着ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。
Chrome在启动过程中崩溃的一个常见原因是在Linux上以
root
用户(administrator
(的身份运行Chrome。虽然在创建WebDriver会话时可以通过传递--no-sandbox
标志来解决此问题,但这种配置是不受支持的,并且非常不鼓励。您需要将环境配置为以常规用户身份运行Chrome
以常规用户身份执行测试。
参考文献
你可以在中找到一些详细的讨论
- WebDriverException:未知错误:尝试启动Chrome浏览器时,DevToolsActivePort文件不存在
- 未知错误:在ubuntu上执行Selenium UI测试用例时,DevToolsActivePort文件不存在错误
- 测试立即失败,出现未知错误:通过systemd运行Selenium网格时,DevToolsActivePort文件不存在