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

Popular posts from this blog

Some good Resources / Blogs / Sites for Selenium Users

Here I have listed out some good blogs and sites by extensive selenium automation users. Hope these will help you a lot. http://automationtricks.blogspot.com  - by NirajKumar http://www.theautomatedtester.co.uk/ http://testerinyou.blogspot.com   - by Naga/Mathu http://seleniumready.blogspot.com  - by Farheen Khan http://seleniumdeal.blogspot.com/  - Amit Vibhuti http://seleniumexamples.com/blog Sauce Labs and BrowserMob are companies doing cloud and extensive selenium automation services, products, etc http://saucelabs.com/blog http://blog.browsermob.com http://testingbot.com/ Cedric Beust -  creator of the TestNG Java testing framework. http://beust.com/weblog/ http://blog.reallysimplethoughts.com/  - by Samit Badle, Created many Selenium IDE Plug-Ins Available Colud Testing: 1. SauceLabs 2. Soasta 3. BrowserMob 4. CloudTesting.com  etc. Selenium Testing Products: 1. Twist by ThoughtWorks 2.  TestMaker by  PushToTest 3. Element34 company providi

UFT - Take full page screenshot by scrolling the page

'######################################################################################## 'This is navigate through the full page and taking individual screenshot of visible area '######################################################################################## Function TakeScreenshot Dim intScrolls, intScroll, strScrollPos Set pgApp = Browser ( " " ) .Page ( " " ) intScrolls = Round ( pgApp . RunScript ( " document.documentElement.scrollHeight / (screen.height) " ) , 2 ) If intScrolls < 1 Then intScrolls = - 1 pgApp . RunScript " window.scrollTo(0, 0); " Wait 1 Browser ( " " ) .CaptureBitmap " C:\screenshot0.png " , True For intScroll = 0 To intScrolls If Environment . Value ( " Browser " ) = " CHROME " Then strScrollPos = " scrollY " Else strScrollPos = " document.documentElement.scrollTop " End If If p

Change IE Browser ZOOM settings

Lot of UI automation testers could have faced this problem as we could change the zoom settings while operating manually for our convenience and forgot to reset to 100%. But our QTP and some other related tools would operate the browser perfectly if browser zoom is 100%. So wee need to change the zoom before start to run the scripts. Its better to have a code snippet in our framework to change this zoom setting right? Here we go... 1. We can simply change the Registry values before Invoking IE Function  ChangeRegistry   Dim  objShell   Set  objShell =  CreateObject ( "WScript.Shell" )  objShell.RegWrite  "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom\ZoomFactor" ,  "100000" ,  "REG_DWORD"   Set  objShell =  Nothing End   Function This option is very useful. But in real time, lot of customers could have restricted write access to windows registry. So we can try other options. 2. Use IE COM object and Change