allow uploading files with forms

This commit is contained in:
Hubert Łępicki 2011-07-18 23:16:57 +02:00
parent 26594c1aa5
commit a4490083b6
3 changed files with 14 additions and 0 deletions

View File

@ -132,3 +132,12 @@ bool WebPage::render(const QString &fileName) {
return buffer.save(fileName);
}
QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile) {
Q_UNUSED(parentFrame);
Q_UNUSED(suggestedFile);
QString javascript = QString("Capybara.lastAttachedFile");
return currentFrame()->evaluateJavaScript(javascript).toString();
}

View File

@ -25,6 +25,7 @@ class WebPage : public QWebPage {
virtual void javaScriptAlert(QWebFrame *frame, const QString &message);
virtual bool javaScriptConfirm(QWebFrame *frame, const QString &message);
virtual bool javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result);
virtual QString chooseFile(QWebFrame * parentFrame, const QString &suggestedFile);
private:
QString m_capybaraJavascript;

View File

@ -1,6 +1,7 @@
Capybara = {
nextIndex: 0,
nodes: {},
lastAttachedFile: "",
invoke: function () {
return this[CapybaraInvocation.functionName].apply(this, CapybaraInvocation.arguments);
@ -106,6 +107,9 @@ Capybara = {
node.checked = (value == "true");
this.trigger(index, "click");
this.trigger(index, "change");
} else if(type == "file") {
this.lastAttachedFile = value;
this.trigger(index, "click");
} else {
node.value = value;
}