JakeT
JakeT

Reputation: 41

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

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

Upvotes: 4

Views: 7677

Answers (1)

breakline
breakline

Reputation: 6073

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.

Upvotes: 3

Related Questions