0

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?

andrewsi
  • 10,807
  • 132
  • 35
  • 51

1 Answers1

0

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);
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313