我想做一个这样的小项目:
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions options = new ChromeOptions();
//... optionsSetupHere
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("https://www.wikipedia.org");
driver.quit();
return "done";
在一个aws lambda serverless上的docker容器内然而,无论我做什么,我仍然得到其中之一:
1)的
[1669291624.447][SEVERE]: bind() faiChromeDriverl ed: Cannot asswas started successfulign requested address (99)
Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[1669276586.713][SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)
ChromeDriver was started successfully.
[1669276589.300][SEVERE]: CreatePlatformSocket() failed: Address family not supported by protocol (97)
Could not start a new session. Response code 500. Message: unknown error: unable to discover open window in chrome
我完全不知道还有什么问题。我知道很多人都遇到过chrome和chromedriver的问题,但没有一个对我有效。所以在这里我列出了我已经尝试过的所有chromedriver选项:
options.addArguments("--headless");
options.addArguments("--start-maximized");
options.addArguments("--no-sandbox");
options.addArguments("--test-type");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("--disable-extensions-file-access-check");
options.addArguments("--incognito");
options.addArguments("--disable-infobars");
options.addArguments("--disable-gpu");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-notifications");
options.addArguments("--window-size=1980,1080");
options.addArguments("--single-process");
options.addArguments("--disable-extensions");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--disable-web-security");
options.addArguments("--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"");
我的设置:Selenium:4.6.0铬驱动程序:107.0.5304.62镀铬:107.0.5304.87-1号双筒钢管
我使用的基本映像是markhobson/maven-chrome我的dockerfile基本上是上面的+ Lambda运行时模拟器,如果有人觉得它有用的话,这里是link
FROM --platform=linux/amd64 markhobson/maven-chrome:jdk-8 as base
FROM base as build
WORKDIR /src
ADD pom.xml .
RUN mvn dependency:go-offline dependency:copy-dependencies
ADD . .
RUN mvn package
# Create final image
FROM base
WORKDIR /function
COPY --from=build /src/target/dependency/*.jar ./
COPY --from=build /src/target/*.jar ./
# Lambda env config
ENTRYPOINT [ "/usr/local/openjdk-8/bin/java", "-cp", "./*", "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" ]
CMD [ "example.App::sayHello" ]
我可以补充说,它的工作与Headless Chromium ,而不是铬罚款,但整个点我触摸这是从Headless Chromium 切换到铬。
我也尝试过将chrome和chromedriver放在/tmp目录中,尽管这不重要,因为它在docker容器中
我还可以补充说,我已经厌倦了使用这个link,并在这些图像和交换处理程序中安装java,但它给出了同样的错误(即使来自repo的python脚本按预期工作)
公平地说,当我还在为Java Docker Lambdas(link)在Amazon Base Image上尝试执行此操作时,我无法通过Yum安装Chrome,并且在那里我得到了其他错误:无法在chrome二进制文件所在的路径中找到它。chrome二进制文件是按如下方式解压缩的:link
可能忘了提到许多其他的解决方案,我已经尝试过,但职位是长反正。
如果有人能帮我我会永远感激你
1条答案
按热度按时间qyswt5oh1#
请尝试使用WebDriverManager库,而不是手动处理Web驱动程序。添加此依赖项:
代替:
把这个:
库将自动检测您的操作系统,并下载正确的webdriver。让我知道结果是什么。