-
-
Notifications
You must be signed in to change notification settings - Fork 181
Closed
Description
Executing the following code will cause a ClassCastException
try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setMaxInMemory(500);
HtmlPage page = webClient.getPage("http://www.shanghai.gov.cn/nw2/nw2314/nw2319/nw41893/index8.html");
HtmlAnchor a;
// Get this tag directly to execute openLinkInNewWindow without problems
a = page.getFirstByXPath("//div[@class='container']/div/div/ul[@class='uli14 pageList']/li[5]/a");
a.openLinkInNewWindow();
a = page.getFirstByXPath("//div[@class='container']/div/div/ul[@class='uli14 pageList']/li[4]/a");
a.openLinkInNewWindow();
// If the previous tag is executed first, then executing this tag will cause a ClassCastException.
// The exception message is com.gargoylesoftware.htmlunit.UnexpectedPage cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlPage
a = page.getFirstByXPath("//div[@class='container']/div/div/ul[@class='uli14 pageList']/li[5]/a");
a.openLinkInNewWindow();
}
Metadata
Metadata
Assignees
Labels
No labels