I'm trying to upload a photo to vk.com 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 = 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()
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.
Any help would be super great.
Thanks.