gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:23:11 25 4
gpt4 key购买 nike

我正在尝试在 Linux 上的 chromedriver(使用 RemoteWebDriver)中打开一个 url。

我在 driver.get(url) 被调用后截图了。它显示一个空白页。

east-northamptonshire_screenshot.jpg

我在我的本地机器 (Windows) 上试过这个(使用 ChromeDriver 打开一个 url)。它工作正常。

这是我要打开的网址。 "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 版本不受支持。

关于java - Selenium chromedriver 在 linux 上打开一个空白页面而不是 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50894803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com