CreatePlatformSocket()失败:协议不支持地址族,并且无法使用AWS Lambda中的WebDriverManager查找chrome二进制文件

时间:2019-11-01 09:54:07

标签: java selenium aws-lambda selenium-chromedriver webdrivermanager-java

我不知道我在做什么错,但是由于某些原因,尽管我使用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();

POM

<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)

1 个答案:

答案 0 :(得分:0)

此错误消息...

[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 Client 版本是 3.10.0 ,这几乎是 2 年。
  • 您的 JDK版本 1.8.0_201 较旧。

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


解决方案

确保:

  • 已升级到当前级别Version 3.141.59
  • JDK 已升级到当前级别JDK 8u222
  • ChromeDriver 已更新为当前的ChromeDriver v78.0级别。
  • Chrome 已更新为当前的 Chrome版本78.0 级别。 (根据ChromeDriver v78.0 release notes
  • 通过您的 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项。
  • 如果您的基本 Web客户端版本过旧,请通过Revo Uninstaller进行卸载,并安装最新版本的 Web客户端。 li>
  • 进行系统重启
  • 非root用户用户的身份执行@Test
  • 始终在driver.quit()方法内调用tearDown(){},以优雅地关闭和销毁 WebDriver Web Client 实例。

Outro

CreatePlatformSocket() returned an error: An invalid argument was supplied. (0x2726) when trying to access chromedriver through network path