I want to imitate a fake click with qwebelement in a qwebview. I have an answer which works with login good, but here nothing happens:
<input type='hidden' name='name' value='0'> <button id="id0" type="submit" class="btn btn-primary">Show List</button>
my Function:
int WebView::clickButton(QString inputName /* input[name=button] */ )
{
QWebElement document = this->page()->mainFrame()->documentElement();
QWebElement button = document.findFirst(inputName);
if (button.isNull()) {
std::cout << "\33[2K\r" << " => Error: Button could not be found" << std::endl;
return 1;
}
button.evaluateJavaScript("this.click()");
return 0;
}
I test it with:
clickButton("input[name=configcaptcha]");
clickButton("input[id=gethoster]");
clickButton("input[type=submit]");
clickButton("input[class=btn btn-primary]");
but either the Button couln't be found or nothing happens.
qDebug() << "evaluate keyUp script" << webEle.tagName() << webEle.toPlainText();
qDebug() << webEle.evaluateJavaScript( QString("this.keydown()") );
qDebug() << webEle.evaluateJavaScript( QString("this.keypress()") );
qDebug() << webEle.evaluateJavaScript( QString("this.keyup()") );
qDebug() << webEle.evaluateJavaScript( QString("keyup()") );
qDebug() << webEle.evaluateJavaScript( QString("onkeyup()") );
qDebug() << webEle.evaluateJavaScript( QString("this.click()") );
qDebug() << webEle.evaluateJavaScript( QString("click()") );
qDebug() << webEle.evaluateJavaScript( QString("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );dispatchEvent(evObj);") );
qDebug() << webEle.evaluateJavaScript( QString("var evObj = document.createEvent(\"KeyboardEvents\");evObj.initEvent( \"keypress\", true, true, null, false, false, false, false, 115, 0 );dispatchEvent(evObj);") );
https://www.qtcentre.org/threads/39515-QWebElement-evaluateJavaScript-problem