我正在尝试运行位于公司代理后面的 Chrome 无头浏览器。我试过下面的代码。但无法通过它。
public class HeadlessChrome
{
WebDriver driver;
@Test
public void createChromeDriverHeadless() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "D:\\LocalData\\workspace\\Drivers and Libraries\\driver\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("http://user:pwd@server:port");
proxy.setSslProxy("http://user:pwd@server:port");
// chromeOptions.setCapability("proxy", proxy);
chromeOptions.addArguments("--proxy-server=user:pwd@server:port");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("start-maximized");
driver = new ChromeDriver(chromeOptions);
driver.get("http://seleniumhq.org");
Thread.sleep(5000);
System.out.println("Title : " + driver.getTitle());
assertTrue(driver.findElement(By.id("q")).isDisplayed());
driver.quit();
}
}
请帮帮我。