PDA

View Full Version : QWebView evaluateJavaScript don't work with anchor which href is javascript



catchxiaoshuang
7th June 2015, 07:21
Now i open a URL by QWebView in my PyQt code, then i want to trigger a click on an anchor, the anchor code is below:

<a class="btn-bid" href="javascript:;" id="exchange-btn" data-sk="exchange">exchange</a>
and this is my code below:

code = """
document.getElementById("exchange-btn").click()
"""
self.view.page().mainFrame().evaluateJavaScript(co de)
but is did not work for me.
I try the code :document.getElementById("exchange-btn").click() in Firefox and one other browser console(by F12), the code works fine.

There is some error in my code or something missing? My Qt version is 4.8.6 and we can not use jquery in this webpage.
Is there someone can tell me how to solve this problem??

catchxiaoshuang
11th June 2015, 04:48
For some reason, when using findFirstElement of QWebFrame, the isNull() function of return QWebElement return True. so i change to find his parent element and it works. then i run javascript use same line, and it works fine.
good luck for you.