Clicking a button on a web page programmatically with QtWebkit
I have a page with this weird button: http://i49.fastpic.ru/big/2013/0730/18/e6fab472339b1d91801641f73a6af418.jpg
(that's the whole button, I didn't cut anything out).
I have managed to find it on the page (or so I believe) with this code:
@QWebElementCollection buttons = _webView->page()->mainFrame()->findAllElements("button[onclick="send.comment(this);"]");
QWebElement button = buttons.at(0);@
There's only 1 element in buttons, so I assume this is it. What I previously did for clicking buttons is:
And it worked on other pages with other buttons, but with this button it doesn't. I've also tried
To no avail as well. How to do it?
Also tried sending artificial mouse clicks. Doesn't work either, but I wonder if I'm doing something wrong here:
@QPoint globalPos = _webView->mapToGlobal(button.geometry().topLeft() + QPoint(5, 5));
QApplication::postEvent(_webView, new QMouseEvent(QEvent::MouseButtonPress, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
QApplication::postEvent(_webView, new QMouseEvent(QEvent::MouseButtonRelease, globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));@
Interesting thing here is that QApplication::widgetAt(globalPos) returns null. Also, globalPos is outside of my screen (because the web page is pretty long).
if your that's really your button declaration and nothing else you've posted, how should button[onclick="send.comment(this);"]" work? It doesn't have a "onclick" attribute specified.
Do you load an external site or html which is generated by you?
I think the forum engine has eaten some code. Fixed, thanks for pointing out.