How to set value of input(type=“file”) with QWebElement?

  • I'm trying to upload a photo to "": using "QtWebKit": module. The problem I'm facing is inability to properly fill input(type="file")'s value. Here's some related code I use:

    def upload():
    print 'uploading...'
    photoInput ='input[id="photos_upload_input"]')
    assert photoInput, 'No input found'
    photoInput.setAttribute('value', '/Users/elmigranto/Downloads/stuff.png')

    print photoInput.evaluateJavaScript('return this.value;').toString()


    It's reasonable to note, that filling value of file input is impossible from Javascript due to browser security policy. However, it should be possible using Qt API, more specifically, "QWebElement::setAttribute()": method. And that's what I did… with no effect (well, photoInput.attribute('value') returns expected result, but photoInput.evaluateJavaScript('return this.value;').toString() returns empty string, input's onchange handler is also not triggered).

    Setting other attributes is no problem, for example, QWebElement::addClass() works like a charm.

    I'm so frustrated right now... Any help would be super great.

    Note: this is repost from "":

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.