Monday 27 January 2014

How to trigger the web events like change, click, mouseup in QTP?

Testing the web application with QTP involves the biggest challenge of events bound to the html elements with jquery by developers not getting triggered. 

Example - 

Problem (Issue)

For instance, when we select the value from the web combobox (dropdown), HTML dom of the webpage changes. It may change the visibility of the some of the controls like edit boxes or drop downs. It may do some ajax calls to the server by using javascript code.
So basically when we do some operation on the web elements , specific event handlers ( java script code or function) get called. But performing the same operation with QTP may not call these event handlers leading to inability to automate the test cases.

Solutions
To handle this issue we can trigger any event like change, click, double click, mouseup, mousedown etc by using FireEvent method. But if it does not work, you can use the vbscript code as depicted below.

'Create the event object
Set evt =  Browser("ABC").Page("XYZ").Object.createEvent("HTMLEvents")

'Set the event type like change, click, mouseup, mousedown
evt.initEvent "change", true, true

'Dispatch the event on desired object.
Browser("ABC").Page("XYZ").WebList("pqr").Object.dispatchEvent(evt)

Above code was tested on internet explorer 10 and QTP 10. If you have faced similar issue while automating web application, please give details in comment and I will try to help you.


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.