Search This Blog

Thursday, August 19, 2010

How to verify html source in selenium

We can verify the html source with selenium commands

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


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


  1. For Selenium IDE.

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

    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!

  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

  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..

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

    please reply me asap...thankx.

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

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


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

  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

  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.

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

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

  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!!