2

我不知道我做错了什么,但由于某种原因,尽管我使用了 WebDriverManager,但它无法找到 chrome 二进制文件。我将日志放在下面以供参考,但据说它找不到二进制文件(或者它无法下载二进制文件?)我到处都发现了类似的问题,但似乎没有一个解决方案有效。

设置

WebDriverManager.chromedriver()
        .targetPath("/tmp")
        .setup();
ChromeOptions options = new ChromeOptions();
options.addArguments(
        "--no-sandbox",
        "--disable-gpu",
        "--enable-javascript",
        "disable-infobars",
        "--disable-dev-shm-usage",
        "--disable-extensions",
        "--headless",
        "--user-data-dir=/tmp/user-data",
        "--data-path=/tmp/data-path",
        "--homedir=/tmp",
        "--disk-cache-dir=/tmp/cache-dir",
        "window-size=1400,600",
        "log-level=3");
this.driver = (WebDriver) new ChromeDriver(options);
this.driver.manage().deleteAllCookies();
this.driver.manage().window().fullscreen();

聚甲醛

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.10.0</version>
</dependency>

<dependency>
    <groupId>org.seleniumhq.webdriver</groupId>
    <artifactId>webdriver-common</artifactId>
    <version>0.9.7376</version>
</dependency>

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.7.1</version>
</dependency>

日志

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.
Nov 01, 2019 9:41:27 AM java.util.prefs.FileSystemPreferences$1 run
WARNING: Couldn't create user preferences directory. User preferences are unusable.
Nov 01, 2019 9:41:27 AM java.util.prefs.FileSystemPreferences$1 run
WARNING: java.io.IOException: No such file or directory
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 24233
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1572601288.635][SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)
unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-128-181.eu-west-2.compute.internal', ip: '10.128.128.181', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x563e5f6197e9 <unknown>
: org.openqa.selenium.WebDriverException
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-128-181.eu-west-2.compute.internal', ip: '10.128.128.181', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x563e5f6197e9 <unknown>

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:138)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
at Controllers.ChromeDriverController.<init>(ChromeDriverController.java:73)
at Controllers.APIController.createCustomer(APIController.java:735)
at com.amazonaws.lambda.creation.CreateOrg.handleRequest(CreateOrg.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)

新日志

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.
Nov 01, 2019 1:40:32 PM java.util.prefs.FileSystemPreferences$1 run
WARNING: Couldn't create user preferences directory. User preferences are unusable.
Nov 01, 2019 1:40:32 PM java.util.prefs.FileSystemPreferences$1 run
WARNING: java.io.IOException: No such file or directory
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 8973
Only local connections are allowed.
Please protect ports used by ChromeD[1572615634.489][SEVERriver and rE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)
elated test frameworks to prevent access by malicious code.
unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-42-38.eu-west-2.compute.internal', ip: '10.128.42.38', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x55f3c74477e9 <unknown>
: org.openqa.selenium.WebDriverException
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-42-38.eu-west-2.compute.internal', ip: '10.128.42.38', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x55f3c74477e9 <unknown>

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:122)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
at Controllers.ChromeDriverController.<init>(ChromeDriverController.java:73)
at Controllers.APIController.createCustomer(APIController.java:735)
at com.amazonaws.lambda.creation.CreateOrg.handleRequest(CreateOrg.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
4

1 回答 1

1

此错误消息...

[1572601288.635][SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)
unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-128-181.eu-west-2.compute.internal', ip: '10.128.128.181', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x563e5f6197e9 <unknown>
: org.openqa.selenium.WebDriverException
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ip-10-128-128-181.eu-west-2.compute.internal', ip: '10.128.128.181', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.146-93.123.amzn1.x86_64', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x563e5f6197e9 <unknown>

...意味着ChromeDriver无法启动/生成新的WebBrowser ,即Chrome 浏览器会话。

您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:

  • 当您使用时:

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.7.1</version>
    </dependency>
    
  • 大概这会反过来下载并使用最新的chromedriver=78.0

  • chromedriver=78.0的发行说明清楚地提到了以下内容:

支持Chrome 版本 78

  • 大概您正在使用chrome= 78.0
  • 但是您的Selenium 客户端版本是3.10.0,差不多老了2年。
  • 您的JDK 版本1.8.0_201 有点旧

因此JDK v8u201Selenium Client v3.10.0ChromeDriver v78.0Chrome 浏览器 v78.0之间存在明显的不匹配


解决方案

确保这件事:

  • Selenium升级到当前级别版本 3.141.59
  • JDK升级到当前级别JDK 8u222
  • ChromeDriver已更新到当前的ChromeDriver v78.0级别。
  • Chrome已更新到当前的Chrome 版本 78.0级别。(根据ChromeDriver v78.0 发行说明
  • 通过IDE清理项目工作区并仅使用所需的依赖项重建项目。
  • 如果您的基本Web Client版本太旧,请通过Revo Uninstaller卸载它并安装最新的 GA 和已发布版本的Web Client
  • 重新启动系统
  • @Test非 root用户身份执行。
  • 始终driver.quit()tearDown(){}方法内调用以优雅地关闭和销毁WebDriverWeb 客户端实例。

奥特罗

CreatePlatformSocket() 返回错误:提供的参数无效。(0x2726) 尝试通过网络路径访问 chromedriver

于 2019-11-01T11:45:35.383 回答