Pages

Search This Blog

Thursday, August 19, 2010

How to verify html source in selenium

We can verify the html source with selenium commands

<html>
<head>
<title>HTML Source</title>
</head>
<body>
what need to be verifed Text is here we need to verify
</body>
</html>

Script


verifyTrue(selenium.getHtmlSource().matches("^[\\s\\S]*Text is here[\\s\\S]*$"));

above command will verify Text is here in above html srource

verifyTrue(selenium.getHtmlSource().matches("^[\\s\\S]*Text i here[\\s\\S]*$"));

above command will fail because it tries to verify Text i here which is not there in html source

11 comments:

  1. For Selenium IDE.

    <tr>
    <td>verifyHtmlSource</td>
    <td>*Text is here*</td>
    <td></td>
    </tr>
    <tr>
    <td>verifyHtmlSource</td>
    <td>*Text i here*</td>
    <td></td>
    </tr>

    ReplyDelete
    Replies
    1. Basic question here, but how do you actually put the above code into IDE? I'm having a hard time getting it to work!

      Delete
  2. hi Niraj.Do you know how to do white box testing in Junit? If yes,Please tell me how to use verifyForward command.Thanks in advance

    ReplyDelete
  3. Hi Niraj, could you please me on how to verify the following HTML source...


    try { Add('/si/prdview','type=search&prd=NE430,NE431&price=350.00,350.00,12.79&query=exact%3Acoffee%3A&hits=58');
    } catch(err) { /* fail without notification */ }


    From the above source I want to verify whether values 'type,prd,price,query,hits' are present.

    I am using the following code to verify the presence of words once at a time. I want to do it all in one command..

    storeHtmlSource|Source1|
    verifyEval|javascript{storedVars['Source1'].indexOf("type",0) > 0}|true
    verifyEval|javascript{storedVars['Source1'].indexOf("prd",0) > 0}|true

    please reply me asap...thankx.

    ReplyDelete
  4. Hi i found the solution to the above mentioned issue...here u go..

    verifyEval|javascript{storedVars['Source1'].indexOf("type",0) > 0 && storedVars['Source1'].indexOf("prd",0) > 0}|true

    Thanks.

    ReplyDelete
  5. Thanks , it is really a very useful information ...

    ReplyDelete
  6. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete
  7. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  8. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  9. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  10. Very well explained, thanks for all the details and you have covered it from very much basics.Appreciate the time taken to share the same. Will be sharing with other forums.
    Best selenium training institute in chennai


    Thanks for sharing the best practices, will definitely use it as a reference for our projects.Please keep sharing such articles.

    Thanks a lot!!

    ReplyDelete