How to follow the link in QWebKit?
The presence of the DOM of the next 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 the link (href) in QWebKit (specifically QWebPage).
Please note that this is an image that is linked.
I cannot do this (and I do not want to, even if I could), simulating a mouse click, since I do not use QWebView, so I do not have a page.
Assuming you have a QWebElement link in a variable called "link" (located via findFirst or something else):
link.evaluateJavaScript ("var evObj = document.createEvent ('MouseEvents'); evObj.initEvent ('click', true, true); this.dispatchEvent (evObj);")
(This is in Python, but this Javascript matters. And yes, it simulates a mouse click, but since it does not use coordinates, it works fine with unloaded QWebPage.)
Using the DOM click() function of a Java Script on an element does the trick:
QWebPage * page = ...; QWebElement el = page->mainFrame()->findFirstElement("a[href]"); el.evaluateJavaScript("this.click()"); If you have a QWebView and don't need scroll automation, this might help:
const QWebElement &element=__your_element__; QWebView *view =__your_view__; QWebFrame *const frame=view->page()->mainFrame(); QPoint const elemPos=element.geometry().center(); frame->setScrollPosition(elemPos); QPoint const scrollPos=frame->scrollPosition(); QMouseEvent * const impossibleMousePress = new QMouseEvent(QEvent::MouseButtonPress,elemPos-scrollPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier); QMouseEvent * const impossibleMouseRelease = new QMouseEvent(QEvent::MouseButtonRelease,elemPos-scrollPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier); QApplication::postEvent(view,impossibleMousePress); QApplication::postEvent(view,impossibleMouseRelease); 