Skip to main content

Run JavaScript from QTP

Yeah, You can run your pure JavaScript from QTP using RunScript method. Lot of times, we are in need of firing events or simulating actions on web page which is not supported by QTP. At that time, you can use your direct DOM methods and directly execute your script on the web page from QTP like,
  1. Dim MyPage, SearchBox
  2. Set MyPage = Browser("title:=Google").Page("title:=Google")  
  3. Set SearchBox = MyPage.RunScript("document.getElementsByName('q')(0);")
  4. SearchBox.Value="testing"

    'if objects available in frames,
    Set SearchBox = MyPage.RunScript("document.frames(4).document.getElementsByName('q')(0);")

    'OR
    Set objFrame Browser("title:=Google").Page("title:=Google").Frame("title:=something")
    objFrame.RunScript("document.getElementsByName('q')(0);")
Also, you can execute by obtaining actual browser window object if you have IE app like,
  1. Dim IEApp
  2. Set IEApp = CreateObject("InternetExplorer.Application")
  3. IEApp.document.parentWindow.execScript("document.getElementsByName('q')(0);")
In the same way, you have functions to execute a .js file itself. Here they are
  1. 'For browser object
  2. Browser().EmbedScript
  3. Browser().EmbedScriptFromFile
  4. 'For Page and frame objects
  5. Page().RunScript  / Frame().RunScript
  6. Page().RunScriptFromFile  / Frame().RunScriptFromFile


Comments

  1. Your arguments between EMR and Medical Billing System is very comprehensive! Thank you for sharing!
    IOS Training in Chennai |
    iOS Training Institutes in Chennai |
    iOS Training

    ReplyDelete
  2. Thanks for sharing this great article! That is very interesting I love reading and I am always searching for informative articles like this.
    Web Designing Course in chennai |
    web designing training in chennai |
    Web Development courses in Chennai

    ReplyDelete
  3. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 

    Best Devops Training in pune

    ReplyDelete
  4. Very nice post here and thanks for it .I always like and such a super contents of these post......

    selenium training in chennai


    java training in chennai

    ReplyDelete
  5. Read all the information that i've given in above article. It'll give u the whole idea about it.
    Python training in bangalore
    Python course in pune
    Python training in bangalore

    ReplyDelete
  6. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    excel advanced excel training in bangalore
    Devops Training in Chennai

    ReplyDelete
  7. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs interview questions and answers

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs-Training in pune

    ReplyDelete

Post a Comment