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



  • I'm trying to upload a photo to "vk.com":https://vk.com using "QtWebKit":https://qt-project.org/doc/qt-4.8/qtwebkit.html 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 = web.page().mainFrame().documentElement().findFirst('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()":https://qt-project.org/doc/qt-4.8/qwebelement.html#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.
    Thanks.

    Note: this is repost from "stackoverflow.com":http://stackoverflow.com/questions/15255300/how-to-set-value-of-inputtype-file-with-qwebelement.


Log in to reply
 

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