chrome linux java_java – Selenium chromedriver在linux上打开一个...

我试图在linux上打开chromedriver(使用RemoteWebDriver)的URL.

我调用了driver.get(url)之后拍了一张截图.它显示一个空白页面.

我在本地计算机(Windows)上试过这个(使用ChromeDriver打开一个网址).它工作正常.

主要方法:

public static void main(String[] args) throws Exception {

String OS = System.getProperty("os.name").toLowerCase();

WebDriver driver = null;

ChromeDriverService service = null;

boolean isWindows = OS.indexOf("win") >= 0;

logger.info("operating System : " + OS);

if (!isWindows) {

service = new ServerChromeDriver().loadService();

}

driver = new ServerChromeDriver().getPIDriver(service, isWindows);

String url = "https://publicaccess.east-northamptonshire.gov.uk/online-applications/search.do?action=weeklyList";

driver.get(url);

Thread.sleep(3000);

ScreenShot.takeScreenShot(driver);

driver.close();

driver.quit();

service.stop();

}

ServerChromeDriver类:

public ChromeDriverService loadService() throws Exception {

Configuration configuration = new Configuration();

configuration.loadProperties();

Properties props = new Properties();

try {

props.load(new FileInputStream("config//log4j.properties"));

} catch (IOException e) {

logger.error(e);

}

PropertyConfigurator.configure(props);

service = new ChromeDriverService.Builder().usingDriverExecutable(new File(configuration.getChromeDriverPath()))

.usingAnyFreePort().withEnvironment(ImmutableMap.of("DISPLAY", configuration.getDisplay())).build();

service.start();

return service;

}

public WebDriver getPIDriver(ChromeDriverService service, boolean isWindows) {

WebDriver driver;

if (isWindows) {

driver = new LocalChromeDriver().getDriver();

} else {

driver = new ServerChromeDriver().getDriver(service.getUrl());

}

String hostName = new ServerChromeDriver().getHostName(driver);

logger.info("Running the application on host: " + hostName);

return driver;

}

public WebDriver getDriver(URL serviceUrl) {

Configuration configuration = new Configuration();

configuration.loadProperties();

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.addArguments("--headless");

chromeOptions.addArguments("--disable-gpu");

// chromeOptions.addArguments("--start-maximized");

chromeOptions.addArguments("--window-size=1800,1800");

// chromeOptions.addExtensions(new File(configuration.getAdBlockPath()));

System.setProperty("webdriver.chrome.driver", configuration.getChromeDriverPath());

System.setProperty("webdriver.chrome.logfile", configuration.getChromeDriverLogFilePath());

System.setProperty("webdriver.chrome.verboseLogging", configuration.getChromeVerboseLogging());

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

capabilities.setJavascriptEnabled(true);

try {

driver = new RemoteWebDriver(serviceUrl, capabilities);

} catch (Exception e) {

logger.error("Error creating a new chrome instance");

throw new RuntimeException(e.getMessage());

}

driver.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);

return driver;

}

我在用

Headless Chrome : 67.0.3396.62

chromedriver : 2.40.565383

这是我从chromedriver.log文件中找到的

[0617/144457.403693:ERROR:nss_ocsp.cc(601)] No URLRequestContext for NSS HTTP handler. host: crt.comodoca.com

[0617/144457.403801:ERROR:cert_verify_proc_nss.cc(980)] CERT_PKIXVerifyCert for publicaccess.east-northamptonshire.gov.uk failed err=-8179

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值