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.
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.)
Using DOM's click()
Java Script function on the element makes the trick:
QWebPage * page = ...;
QWebElement el = page->mainFrame()->findFirstElement("a[href]");
el.evaluateJavaScript("this.click()");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With