WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser (33个答案)
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd (1个答案)
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu (12个答案)
1年前关闭。
我有一项新任务,要在Mac上自动化 Electron 应用程序。因此,我使用python和selenium来启动任务。
使用流动的代码,我可以启动该应用程序,但是在启动该应用程序后,自动化脚本将挂起,甚至无法打印一些消息。
现在是我的代码:
from time import sleep
from selenium import webdriver
def startdriver():
print("start service")
service = webdriver.chrome.service.Service("chromedriver")
service.start()
print("started")
print(service.service_url)
caps = {
'browserName': 'chrome',
'goog:chromeOptions': {
'args': ['--no-sandbox',
'--disable-dev-shm-usage'],
'binary': r"/Applications/Enterprise.app/Contents/MacOS/Enterprise",
'extensions': [],
'windowTypes': ['webview']},
'platform': 'ANY',
'version': ''}
print(caps)
driver = webdriver.remote.webdriver.WebDriver(
command_executor=service.service_url,
desired_capabilities=caps,
#desired_capabilities={'chromeOptions': caps},
browser_profile=None,
proxy=None,
keep_alive=False)
sleep(4)
print("start")
driver.get("http://www.google.com")
这是脚本的输出:
start service
started
http://localhost:50506
{'browserName': 'chrome', 'goog:chromeOptions': {'args': ['--no-sandbox', '--disable-dev-shm-usage'], 'binary': '/Applications/Enterprise.app/Contents/MacOS/Enterprise', 'extensions': [], 'windowTypes': ['webview']}, 'platform': 'ANY', 'version': ''}
大约1分钟后,该应用程序关闭,脚本显示:
Traceback (most recent call last):
File "/Users/leo.wong/auto/Auto/try/try4.py", line 31, in <module>
keep_alive=False)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/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
我曾尝试用Spectron在Java和Javascript中使用类似的代码,这在Electron官方网站上已有提及。但是我看到了同样的事情。
我的环境:
MacOS:10.14.6 Python:3.7 Chrome:版本79.0.3945.88(正式版本)(64位) Chromedriver:ChromeDriver 79.0.3945.36 任何人都知道如何使它正常工作,我想提供更多信息,但是请告诉我我应该提供什么。
此异常可能有多种原因。最常见的问题之一是ChromeDriver版本与 Electron 版本之间的不兼容,您要尝试自动分发的 Electron 应用程序与 Electron 版本不兼容。
例如如果我的应用程序的Electron版本为v7.1.2,则要使用的ChromeDriver版本应为78.0.3904.113。
有关此兼容性的更多信息,请参见此处-
Electron and Chromium version
我尝试使用Java v1.8,Electron v7.1.6(在node_module/.../dist文件夹中创建的默认electronic.exe)和ChromeDriver v78.0.3904.105尝试的示例
ChromeOptions options = new ChromeOptions();
options.setBinary("./electron-quick-start/node_modules/electron/dist/electron.exe");
ChromeDriverService chromeservices = new ChromeDriverService.Builder().build();
WebDriver driver = new ChromeDriver(chromeservices, options);
String chromeVersion = driver.findElement(By.cssSelector("ul > li.chrome-version")).getText();
String electronVersion = driver.findElement(By.cssSelector("ul > li.electron-version")).getText();
System.out.println("Chromium version : " + chromeVersion);
System.out.println("Electron version : " + electronVersion);
driver.quit();