如何跟随QWebKit中的链接? [英] How to follow a link in QWebKit?
问题描述
具有以下html的DOM;
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>
如何在QWebKit(特别是QWebPage)中链接(href).
how to follow a link (href) in QWebKit (specifically QWebPage).
请注意,这是一个链接的图像.
我无法通过模拟鼠标单击来做到这一点(即使我也无法做到),因为我不使用QWebView,因此我无法呈现页面.
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.
推荐答案
假定链接的QWebElement位于名为"link"(通过findFirst或其他方式定位)的变量中:
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);")
link.evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);")
(这是在Python中,但是重要的是Javascript.是的,这是在模拟鼠标单击,但是由于它不使用坐标,因此可以在未渲染的QWebPage上正常工作.)
(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.)
这篇关于如何跟随QWebKit中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!