Monday, October 31, 2011

Running Javascript in QTP

You can run Javascript in QTP using Runscript method. This is a new feature in QTP 11. Here is an example for it.

Set oPage=Browser("name:=Google").Page("title:=Google")

Set oTxtGoogle=oPage.RunScript("document.getElementsByName('q')(0);")
'The above line gets DOM object for Google textbox using Javascript.

oTxtGoogle.Value="qtp"

I hope it is helpful.

5 comments:

  1. Hi,

    Thanks for your useful info, but it's not running, any specific reason?

    Thanks,
    Bala

    ReplyDelete
  2. it will work in qtp 11 only

    ReplyDelete
  3. Is QTP able to run the javascript that is present on the client side. My use case is I want to write load tests for my web application which has a lot of YUI widgets and javascript and I want that the load test should be able to run the javascript present in the HTML page.

    ReplyDelete