ChromeDriver。连接到Chrome超时。 Linux Debian服务器

时间:2018-10-29 09:50:31

标签: java linux selenium server selenium-chromedriver

我有一个Java应用程序,它以--headless模式使用ChromeDriver作为WebDriver来解析网站。

我使用maven-assembly-plugin将其组装成具有依赖关系的jar。在我的本地debian机器上,该应用程序启动并正常运行。但是,当我尝试在没有gui的专用debian服务器上启动它时,它会显示以下信息:

$ java -jar parser-1.0-SNAPSHOT-jar-with-dependencies.jar 
Starting ChromeDriver 2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 13694
Only local connections are allowed.
[1540730919.752][WARNING]: Timed out connecting to Chrome, retrying...
[1540730923.752][WARNING]: Timed out connecting to Chrome, retrying...
[1540730931.752][WARNING]: Timed out connecting to Chrome, retrying...
[1540730947.753][WARNING]: Timed out connecting to Chrome, giving up.
[1540730949.758][WARNING]: Timed out connecting to Chrome, retrying...
[1540730953.758][WARNING]: Timed out connecting to Chrome, retrying...
[1540730961.758][WARNING]: Timed out connecting to Chrome, retrying...

我在服务器上安装了chrome-stable,default-jdk和chromedriver,因此从理论上讲应该可以工作。

这是WebDriver初始化的代码

System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1200x600");
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
options.addArguments("--disable-notifications");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

出什么问题了? 谢谢。

2 个答案:

答案 0 :(得分:1)

我在Win 10上遇到Selenium Webdriver + Jmeter的问题,如下所示。是我系统上的安全应用程序“ Sophos”将其阻止。

我通过禁用系统上正式安装的安全应用程序来修复它。现在可以正常工作了。

Starting ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a) on port 46315
Only local connections are allowed.
[1540910061.181][WARNING]: Timed out connecting to Chrome, retrying...
[1540910065.184][WARNING]: Timed out connecting to Chrome, retrying...
[1540910073.193][WARNING]: Timed out connecting to Chrome, retrying...
[1540910089.193][WARNING]: Timed out connecting to Chrome, giving up.
[1540910091.196][WARNING]: Timed out connecting to Chrome, retrying...
[1540910095.196][WARNING]: Timed out connecting to Chrome, retrying...
[1540910103.210][WARNING]: Timed out connecting to Chrome, retrying...
[1540910119.210][WARNING]: Timed out connecting to Chrome, giving up.

确保没有安装任何可以阻止此程序的安全应用程序。

答案 1 :(得分:0)

也尝试添加这些参数--disable-software-rasterizer --no-gpu --disable-software-rasterizer --mute-audio --hide-scrollbars--remote-debugging-port=9222