PDA

View Full Version : QWebElement::evaluateJavaScript strange behaviour



piotr.dobrogost
17th April 2010, 15:39
Hi

Variant A does not work but variant B works.
What's the reason?


QWebElement doc = frame()->documentElement();

// variant A


doc.findFirst("input[id='someId']").evaluateJavaScript("click()");

// variant B


doc.findFirst("input[id='someId']").evaluateJavaScript("document.getElementById('someId').click()");

wysota
17th April 2010, 22:17
What if you do this.click()?

piotr.dobrogost
19th April 2010, 22:09
This works. Thanks.

Before I had been using QWebElement::function() which did not get into public API and it was enough to call it with "click" argument. It looks like it was executing js method in context (on behalf) of the element by default.

rbp
11th January 2011, 11:45
I found this.click() doesn't work for other elements like DIV.
I used this workaround:


evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEven t( 'click', true, true );this.dispatchEvent(evObj);")