Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several differences between <code>WebElement(...).FireEvent</code> and <code>WebElement.Object.fireEvent</code> the first runs a QTP function which performs all sorts of work and the second directly goes to the DOM element. Here is a list of a few things that QTP does which aren't done in the native DOM method (there may be more).</p> <ol> <li>If the element isn't visible QTP makes it visible (this includes activating the tab and scrolling into view)</li> <li>QTP support <a href="https://stackoverflow.com/questions/1455212/testing-fly-out-menu-in-qtp/1455924#1455924">device replay</a> in which case it will move the cursor and simulate a real click (this gives you a better simulation of how real people interact with the application)</li> <li>QTP writes to the report that it performed a <code>FireEvent</code> step</li> </ol> <p>As for your problem, in general you can use the native DOM method in order to pass an event object but when I tried it I couldn't get it to work from QTP</p> <pre><code>set doc = Browser("B").Page("P").WebElement("W").Object.ownerDocument set ev = doc.createEventObject() ev.shiftKey = True Browser("B").Page("P").WebElement("W").Object.FireEvent "onclick", ev </code></pre> <p>However something equivalent does work when run from the browser.</p> <p>Starting in QTP11 there's support for running JavaScript files from the script using <code>Page("P").RunScript</code> until that you can simulate this ability manually. The following snippet works for me (I use the object from the repository to get the IE specific <code>uniqueID</code> of the element so I don't have to identify it again).</p> <pre><code>' Use QTP's object identification instead of reproducing the logic in JavaScript id = Browser("B").Page("P").WebElement("W").Object.uniqueID ' Construct JavaScript script script = "var e = document.createEventObject(); e.shiftKey = true; " &amp; _ "document.getElementById('" &amp;id &amp; "').fireEvent('onclick', e);" ' Run it on the browser Browser("B").Page("P").Object.parentWindow.eval script </code></pre> <hr> <p>If all else fails you can try writing a small <a href="http://www.advancedqtp.com/knowledge-base/articles/code-techniques-id15/web-extensibility-lesson-building-a-toolkit-support-2/" rel="nofollow noreferrer">web-extensibility</a> project and support this functionality.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload