One, C++ implementation
- QWebFrame* frame = webView()->page()->currentFrame();
- if (frame!=NULL){
- QWebElementCollection collection1 = frame->findAllElements(“input[name=submit]”);
- foreach (QWebElement element, collection1){
- QPoint poss(element.geometry().center());
- QPoint pos = this->topLevelWidget()->mapToGlobal(QPoint(0,0));
- QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
- QApplication::sendEvent(webView->page(), &event0);
- QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
- QApplication::sendEvent(webView->page(), &event1);
- }
- }
This method is effective for pure HTML webpages, but webpages that implement the submission function by javascript may not be effective.
Two, javascript implementation
transfer
- evaluateJavaScript(code);
Three, the combination of the two to achieve
- QWebFrame* frame = webView()->page()->currentFrame();
- if (frame!=NULL) {
- QWebElementCollection collection1 = frame->findAllElements(“input[name=submit]”);
- foreach (QWebElement element, collection1){
- element.evaluateJavaScript("this.click();");
- }
- }