How to handle a native OS (Ubuntu) file upload window in selenium webdriver with python?



  • This is my first time here but I have already posted this question on SO. I keep getting solutions for Windows + Java and not for Linux or python for that matter.

    I am using Selenium and Python to automate a file upload application for the past many hours but nothing helpful!

    The HTML DOM structure for this file upload is an input tag with its type attribute value = 'file'. I know I can make use of the send_keys.

    The problem is I am not supposed to use send_keys() (as per the question I am trying to solve). The assumption is there are other ways of doing it.

    Can anyone suggest me alternative ways to upload the file? I do get solutions for windows but not for Linux(Ubuntu). I know there are applications/tools to automate GUI components like AutoIt but there is nothing for Linux close to AutoIt.

    I can say I have done my homework to find a solution. Only after not finding anything useful, I am asking this question, please help!



  • Welcome to the club, Praveen; your problem is a rite of passage for Selenium users.

    Instead of trying to automate the file dialog, you may have better luck issuing the same HTTP request that your file upload form would have issued. Issuing a POST request for a file upload is a little bit harder than a GET request because of the encoding issues, but I suspect you know where to look to find the appropriate Python API.

    Another option is to use set_keys() to set the value of the relevant file input element, like this:

    elem = driver.find_element_by_id("file")
    elem.send_keys("/tmp/temp.txt")
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2