微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Selenium chromedriver在linux上打开一个空白页而不是url

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

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

east-northamptonshire_screenshot.jpg

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

这是我试图打开的网址. “https://publicaccess.east-northamptonshire.gov.uk/online-applications/search.do?action=weeklyList

主要方法

 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;
}

应用程序正在为此URL工作:https://eplanning.birmingham.gov.uk/Northgate/PlanningExplorer/GeneralSearch.aspx

birmingham_screenshot.jpg

我在用

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

解决方法:

我认为因为Linux机器中的Chrome版本不受支持.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐