I have a HTML page with <input type=file>
I'm using QtWebkit and I'm already able to get the QWebElement of the INPUT type.
How do I set its value to a specific string (file path) so I can submit the form?
I have a HTML page with <input type=file>
I'm using QtWebkit and I'm already able to get the QWebElement of the INPUT type.
How do I set its value to a specific string (file path) so I can submit the form?
A naive thing to do would be to set the value
attribute of the input
element.
element->setAttribute("value", "path");
This is will not work, though, since you're not allowed to set this attribute unless you're "the browser".
Probably the way to go is to use the mozSetFileNameArray
, like so:
const QString filePath = "/foo/bar/baz"; // or "C:\foo\bar\baz"
const QString js = QString(
"var fileArray = {'%1'};"
"this.mozSetFileNameArray(fileArray, fileArray.length);"
).arg(filePath);
element->evaluateJavaScript(js);