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

Trying to do tutorial examples in HtmlUnit so that I can connect to web pages via 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

+3


source to share


1 answer


Most likely the org.w3c.css: sac dependency is missing , see the SAC project page for more information. Include it in your POM or put the jar on the classpath.



+1


source







All Articles