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. IOT Training in Bangalore - Live Online & ClassroomStudents are made to understand the type of input devices and communications among the devices in a wireless media.IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication.

    ReplyDelete
  4. Selenium is one of the most popular automated testing tool used to automate various types of applications. Selenium is a package of several testing tools designed in a way for to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms and for the same reason, it is referred to as a Suite.

    Selenium Interview Questions and Answers
    Javascript Interview Questions
    Human Resource (HR) Interview Questions

    ReplyDelete
  5. 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
  6. 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
  7. 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
  8. 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

  9. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
    Advanced AWS Training in Chennai | Best Amazon Web Services Training in Chennai
    Best Amazon Web Services Training Course in Bangalore | AWS Training in Bangalore
    AWS Online Training and Certification | AWS Certification Course

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

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 EndFunction 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 Settings
Function ChangeIEZoom Dim intZoomLevel, objIE  intZoo…

QTP - Object Identification - Prerequesties

While starting a new project or proof of concept or after new QTP installation, we would face the issue in identifying objects as QTP built objects like WinList, WebEdit, etc.; instead everything will be identified as WinObject.

Here are some steps to ensure you did the environment setup RIGHT before start automating.
Did you enabled required Add-ins only while launchingDid you selected "Record >> Record and Run Settings" - This should be based on what type of application you are working with
Windows app - Windows >> Record and run test on any windows applications. Web app - Web >> Record and run test on any open browser.
Did you tried to launch UFT/QTP and then AUT.If its web, ensure browser zoom level set to 100%Try disabling the protected mode in IE for web.Launch UFT and AUT using RUN AS ADMINISTRATORAlso see the Object Identification Methods if you are interested.