无法启动浏览器(Chrome、Edge 等)我有最新版本的
Chrome : 126
、Selenium : 4.22.0
、java.version: '22.0.1'
。
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Host info: host: 'DESKTOP-KT75J6U', ip: '192.168.1.37'
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:536)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:51)
at framework.BrowserTest.main(BrowserTest.java:9)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to bind the port.
Build info: version: '4.22.0', revision: 'c5f3146703*'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '22.0.1'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:249)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:117)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
... 7 more
您的 chromium 配置为使用远程驱动程序而不是本地驱动程序。就我而言,这是我删除的额外依赖项
org.seleniumhq.selenium:selenium-remote-driver
另一个值得关注的地方,事实证明,Selenium 没有足够好的错误处理能力。我建议仔细检查二进制文件的路径是否设置正确。重要提示:正如我发现的,路径不应包含空格或特殊字符。如果有的话,它会崩溃并出现非常模糊的错误
var options = new ChromeOptions();
options.setBinary("/path/to/chromium/chromium.app/Contents/MacOS/chromium");