0

I'm unable to upload and save an image.

The following is the piece of code that facilitates file upload using the UI. At first, only the upload button is visible and once an image is selected from the uploader the save button is visible.

 <td colspan="1" class="actions">
                <input type="button" class="button" name="logo" id="logo-f-upload" value="Upload Image"/>
                <input type="file" id="logo-upload" accept="image/*" name="logo-upload" style="display:none" />
                <input type="submit" value="click to save" name="submit_logo_now" class="main submit_dm logo-save-focused" style="display: none"/>
                </br>
</td>

I tried driver.find_element_by_id("logo-f-upload").send_keys(os.getcwd()+"/image_test.png")

and also

driver.find_element_by_id("logo-upload").send_keys(os.getcwd()+"/image_test.png")

but it doesn't throw any error at this stage but on the next where it says "element is not visible ..." ie. the save button. On the UI, when simulating this, the file uploader doesn't open but the file_upload button value changes to the path of the image and then breaks.

7
  • Have you looked at this? Commented May 25, 2014 at 10:49
  • I'm using Linux and the input type is not MULTI so I don't think that may be the solution. Commented May 25, 2014 at 10:54
  • So the problem is that 'logo-upload' is not visible on the screen while logo-f-upload is, although logo-upload is the input of type = file. Any idea what I can do now? Commented May 26, 2014 at 13:14
  • What does dir(driver.find_element_by_id("logo-upload")) say? Maybe there's something special about input tags. Commented May 26, 2014 at 13:17
  • Do you need to put a return character in the send_keys? Commented May 26, 2014 at 13:26

1 Answer 1

1

I believe this is the answer which is merely a JS hack: So the problem is that the logo-upload input has style set to display:none and due to this, selenium can't find the element. The solution that works for me is using javascript to set the style to display:block, after which using send_keys(img_path) works fine.

dr.execute_script("document.getElementById('logo-upload').setAttribute('Style','display:block')")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.