qt+evaluatejavascript
2016-04-11 20:02
459 查看
think the
click()failuremay have something to do with how the google page uses javascript to transform the original
Aelementafter it loads. If you wrap your
evaluateJavaScript()callin an
alert(),you can see that the
clickmethodis
null
link.evaluateJavaScript('this.click')It is not a 100% cross-browser support to be able to call "click" on a link. It would need to be a button.You have a couple alternatives...(#1) Just navigate to the href of the link
def _loadComplete(self): page = self.page() doc = page.currentFrame().documentElement() link = doc.findFirst('#link-signup') if link and not link.isNull(): self.load(QUrl.fromEncoded(link.attribute('href').toAscii()))(#2) Simulate a click on the web view
def _loadComplete(self): page = self.page() doc = page.currentFrame().documentElement() link = doc.findFirst('#link-signup') if link and not link.isNull(): pos = link.geometry().center() self._doMouseClick(page, pos) else: print "Link not found" @staticmethod def _doMouseClick(obj, pos): # mouse down evt = QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(obj, evt) # mouse up evt = QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(obj, evt)(#3) Make the link clickable via javascript
def _loadComplete(self): page = self.page() doc = page.currentFrame().documentElement() link = doc.findFirst('#link-signup') if link and not link.isNull(): link.evaluateJavaScript(""" var e = document.createEvent('MouseEvents'); e.initEvent('click', true, true); this.dispatchEvent(e);
""")原文地址:http://stackoverflow.com/questions/13553817/pyqt4-does-not-redirect-me-to-the-next-page/13554601#13554601[/code]
相关文章推荐
- js和qt4 evaluteJavascript
- js练习题:网页换肤
- 获取前端post方式传过来的JSON格式的数据的代码
- js学习笔记3
- javaScript获取浏览器窗口可视区域大小
- JavaScript(1)
- js: how to get length of dict
- jsp中获取客户ip及其他资料的方法
- 【JS】:JS做的一个闹钟
- Jsp基础
- javascript学习笔记w3chool
- 【js】:js中对于两种控件不同的值得显示方法
- enum枚举定义转json
- 最近兰州的js风格写个插件和一个template engine
- [转]深入详解javascript之delete操作符
- Json.NET
- DataTable.js
- [代码片段]javascript检查图片大小和格式
- [JS]js来取iframe框架中的内容源代码参考
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)