Adder
Adder

Reputation: 5868

HttpUnit - how to use getTextBlocks

I would like to know how I can access all texts in a web page using http unit. The problem I have is that getTextBlocks only seems to return texts in h1 .. h6 tags. I would like to find the text "Support LS" that is contained in the below HTML fragment. Excuse my short question, but googling for httpunit getTextBlocks doesn't return many useful matches. I wonder whether I have to descend the text blocks recursively, since each text block seems to have a getTextBlocks - method.

    TextBlock[] texts;
    try {
        texts = actualResponse.getTextBlocks();
    } catch (SAXException e) {
        e.printStackTrace();
        return e.toString();
    }

    errorMessage = "Did not find needle " + webService.getWebServiceNeedle();
    for(int i = 0; i<texts.length; ++i) {
        TextBlock tb = texts[i];
        if(debugMode) {
            logger.debug("Web Check " + webService.getWebServiceName() + " Text =" + tb.getText());
        }
        if(tb.getText().indexOf(webService.getWebServiceNeedle()) >= 0) {
            logger.info("Found needle" + webService.getWebServiceNeedle());
            errorMessage = null;
            break;
        }
    }

<!-- <body> -->
<header class="clsHead">
            <div>
                <a href="#wrapper" id="menu-toggle" class="glyphicons glyphicons-show-lines clsMenuMain"></a>
            </div>
            <div>
                <span class="clsHeadFont"> 2.0 </span>   
            </div>   
               <div>
                    <marquee id="flashMessage" style="position: absolute;bottom: 18px;left:240px;" class="span8" scrollamount="4"></marquee> 
                  </div>  
             <div class="CLSuserloginadmin">
            <!--  <span ><div style="float:right">

            </div></span> -->

        <span class="clsHeadFont1">Welcome, Support LS</span> <span
            class="clsHeadFont1 clsHeadLogPad"> | </span> <a href="logout">Logout </a>

            <a class="dropdown-toggle" data-toggle="dropdown"><img
            class=""
            src="/rator-monitoring/resources/img/setting.png"
            id="lodindb"
            style="width: 28px; margin-top: -5px; padding-left: 11px;"></a>

            <ul class="dropdown-menu" role="menu">
                <li class="version">About</li>
                <li class="preferences">User Preferences</li>                                             
            </ul>


    </div>



 </header>

Upvotes: 1

Views: 47

Answers (0)

Related Questions