Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set value of input(type="file") with QWebElement?
    primarykey
    data
    text
    <p>I'm trying to upload a photo to <a href="https://vk.com" rel="nofollow">vk.com</a> using <a href="https://qt-project.org/doc/qt-4.8/qtwebkit.html" rel="nofollow">QtWebKit</a> module. The problem I'm facing is inability to properly fill <code>input(type="file")</code>'s value. Here's some related code I use:</p> <pre class="lang-python prettyprint-override"><code>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() </code></pre> <p>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, <a href="https://qt-project.org/doc/qt-4.8/qwebelement.html" rel="nofollow"><code>QWebElement</code></a><code>::</code><a href="https://qt-project.org/doc/qt-4.8/qwebelement.html#setAttribute" rel="nofollow"><code>setAttribute()</code></a> method. And that's what I did… with no effect (well, <code>photoInput.attribute('value')</code> returns expected result, but <code>photoInput.evaluateJavaScript('return this.value;').toString()</code> returns empty string, input's <code>onchange</code> handler is also not triggered).</p> <p>Setting other attributes is no problem, for example, <a href="https://qt-project.org/doc/qt-4.8/qwebelement.html" rel="nofollow"><code>QWebElement</code></a><code>::</code><a href="https://qt-project.org/doc/qt-4.8/qwebelement.html#addClass" rel="nofollow"><code>addClass()</code></a> works like a charm.</p> <p>Any help would be super great.<br/>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload