Skip to content

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

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();

        }

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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