下面是我用来初始化chrome webdriver的代码片段:
System.out.println("Initializing Chrome");
ChromeOptions options = new ChromeOptions();
//options.setBinary("C:/Program Files (x86)/Google/Chrome/Application");
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches",new String[]{"enable-automation"});
options.addArguments("--disable-extensions");
options.addArguments("--disable-infobars");
options.addArguments("--allow-running-insecure-content");
WDriver = new ChromeDriver(options);
//WDriver = new ChromeDriver();
WDriver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
System.out.println("Chrome Initialization Complete");
但是似乎要打开两个chrome实例,这将显示在控制台上:
Initializing Chrome
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-
heads/3904@{#800}) on port 12262
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious
code.
Nov 04,2019 3:29:38 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session,assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger
(org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[1572910181.451][WARNING]: Timed out connecting to Chrome,retrying...
Nov 04,2019 3:29:43 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
[1572910186.002][WARNING]: Timed out connecting to Chrome,2019 3:29:48 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Chrome Initialization Complete
Chrome版本:78.0.3904.87
Chromedriver版本:chromedriver_78.0.3904.70
硒版本:3.141.59
虽然问题不是主要障碍,但它打开chrome的第二个实例会很烦人,它将在待机状态下占用内存。
干杯。