python webdriver os window
Question: I need to upload a file using Python and Selenium. When I click the upload
HTML element a "File Upload" window is opened and the click() method does not
return since it waits to fully load the page. Therefore I cannot continue
using pywinauto code to control the window.

The first method clicks the HTML element (an img) to upload a new file:

    
    
    def add_file(self):
        return self.selenium.find_element(By.ID, "add_file").click()
    

and the second method is using pywinauto to type the path to the file and then
click open

    
    
    def upload(self):
        from pywinauto import application
        app = application.Application()
        app.connect_(title_re = "File Upload")
        app.file_upload.TypeKeys("C:\\Path\\To\\FIle")
        app.file_upload.Open.Click()
    

How can I force add_file method to return and to be able to run the upload
method?


Answer: Solve it. There was an iframe dealing with the upload but was hidden and
didn't see it in the first place. The iframe contains an input of type file
also hidden. To solve it make the iframe visible using javascript:

    
    
    selenium.execute_script("document.getElementById('iframe_id').style.display = 'block';")
    

then switch to the iframe and make the input visible also:

    
    
    selenium.switch_to_frame(0)
    selenium.execute_script("document.getElementById('input_field_id').type = 'visible';")
    

and simply send the path to the input:

    
    
    selenium.find_element(By.ID, 'input_field_id').send_keys("path\\\\to\\\\file")
    

For windows use 4 '\\\\\\\' as path separator.

