Search in sources :

Example 1 with HtmlHeading1

use of com.gargoylesoftware.htmlunit.html.HtmlHeading1 in project tutorials by eugenp.

the class HtmlUnitWebScrapingLiveTest method givenBaeldungArchive_whenRetrievingArticle_thenHasH1.

@Test
public void givenBaeldungArchive_whenRetrievingArticle_thenHasH1() throws Exception {
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setJavaScriptEnabled(false);
    final String url = "http://www.baeldung.com/full_archive";
    final HtmlPage page = webClient.getPage(url);
    final String xpath = "(//ul[@class='car-monthlisting']/li)[1]/a";
    final HtmlAnchor latestPostLink = (HtmlAnchor) page.getByXPath(xpath).get(0);
    final HtmlPage postPage = latestPostLink.click();
    final List<HtmlHeading1> h1 = (List<HtmlHeading1>) postPage.getByXPath("//h1");
    Assert.assertTrue(h1.size() > 0);
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlHeading1(com.gargoylesoftware.htmlunit.html.HtmlHeading1) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) List(java.util.List) Test(org.junit.Test)

Aggregations

HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 HtmlHeading1 (com.gargoylesoftware.htmlunit.html.HtmlHeading1)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 List (java.util.List)1 Test (org.junit.Test)1