4

Trying to do the tutorial examples on HtmlUnit so I can connect to web pages through Java. I am getting the following error when I try to run it:

java.lang.NoClassDefFoundError: org/w3c/css/sac/ErrorHandler stack overflow

Here is my code:

package Http;


import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Assert;
import org.junit.Test;

public class Facebook {
    @Test
    public void homePage() throws Exception {
        try (final WebClient webClient = new WebClient()) {
            final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
            Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());

            final String pageAsXml = page.asXml();
            Assert.assertTrue(pageAsXml.contains("<body class=\"composite\">"));

            final String pageAsText = page.asText();
            Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"));
        }
    }
}

I have httpcore 4.4.1 httpclient 4.4.1 htmlunit.2.17 all imported

1 Answer 1

3

You're most likely missing the dependency org.w3c.css:sac, see SAC project page for further information. Include it in your POM or put the jar in the classpath.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.