Saturday, September 19, 2015

Selecting the drop down value that trigger the onchange event in webpage


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 of Problem

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.

Solution
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 IE 10 with QTP 10.

No comments:

Post a Comment