views:

469

answers:

1

Having a DOM of the following html;

<a href="?op=order">
<img class="img_button" src="picture.gif"
  onMouseOver="this.src='some.gif';"
  onMouseOut="this.src='some_other.gif';"
  alt="" border="0">
</a>

how to follow a link (href) in QWebKit (specifically QWebPage).

Please notice that it's an image that is linked.
I can't do it (and I don't want to even if I could) by simulating a mouse click as I don't use QWebView thus I don't have the page rendered.

A: 

Assuming you have the link's QWebElement in a variable called "link" (located through findFirst or whatever):

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

(This is in Python, but it is the Javascript that matters. And yes, this is simulating a mouse click, but since it does not use coordinates, it works fine with an unrendered QWebPage.)

Mikael