selenium for Ghost Browser / Chromium based browser, execution problems

selenium for Ghost Browser / Chromium based browser, execution problems

我目前正在尝试为 Ghost 浏览器(基于 Chromium 的浏览器)编写脚本。

ChromeOptions options = new ChromeOptions();
    options.setBinary("C:\Users\Admin\AppData\Local\GhostBrowser\Application\ghost.exe");
    ChromeDriver driver = new ChromeDriver(options);
    
    driver.get("https://www.google.com");
    

我把ChromeDriver的二进制路径设置为Ghost浏览器的路径

当我执行时,它执行了但立即关闭,并给出以下错误。 我不知道如何处理它,或者要设置什么参数才能使其工作, 请帮忙

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 51746
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. session not created: Chrome version must be between 71 and 75
  (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.19043 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.09 seconds
Build info: version: '4.1.0', revision: '87802e897b'
System info: host: 'ADMIN-PC', ip: '10.6.0.129', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\Admin\AppData\Loca..., extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\Admin\AppData\Loca..., extensions: []}}}]
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:217)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:169)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler[=11=](JsonWireProtocolResponse.java:54)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction[=11=](HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession(ProtocolHandshake.java:133)
    at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:197)
    at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:1002)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:135)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:139)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:246)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:168)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:104)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:91)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:80)
    at extras.testclass.main(testclass.java:16)

这个错误信息...

Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 51746

...表示 was unable to initiate/spawn a new Browsing Context i.e. 会话。

您的主要问题是您使用的二进制文件版本之间不兼容

  • 您使用的 chromedriver=2.46 非常古老。

解决方案

确保:


更新

您需要下载最新的 e.g. ChromeDriver v98.0.4758.102 and store it in your system. Next you have to mention the absolute path of the chromedriver executable through 行如下:

System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\Users\Admin\AppData\Local\GhostBrowser\Application\ghost.exe");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");