Skip to content

WebClient#openWindow will cause a ClassCastException exception in some cases #84

@ly641921791

Description

@ly641921791

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions