title: How to have Selenium select a file from a file explorer opened by a webpage
body: <p>Ok, so this is a little difficult to explain so I shall start with the words and then get into a bit of code. I am using a database software called airtable, which does not allow me to upload images through the API. However a user can upload an image through a form submission, which creates a new record in the base. I am getting around the lack of automated uploading by using Selenium and opening the webform, then entering the data as a user. The problem I have run into is when I try and upload a file. I cannot send the filepath to the attachment space, and it seems that I am forced to interact with the windows File Explorer popup instead. I have read the answers to <a href="https://stackoverflow.com/questions/19116392/how-to-handle-windows-file-browse-window-using-selenium-webdriver">this</a> question, and tried using win32com, autoit, and the selenium switch to window functions. All without apparent results. So that is the state of things here, and I shall now show an example of what I am trying to do.</p>
  <p>First up I have this code, which opens the form seen below it. Url and driver_path are defined, but not shown here</p>
  <pre><code>driver = webdriver.Firefox(executable_path=driver_path)
  driver.get(url)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/OPHWb.png" rel="nofollow noreferrer">Image of the form as it opens initially</a></p>
  <p>Now I have tried to pass a filepath here, but none of the objects seem to be reachable by keyboard. Instead I use this brief code to click on the button</p>
  <pre><code>attach = driver.find_element_by_xpath(&quot;//div[@class='fsp-drop-area']&quot;)
  attach.click()
  </code></pre>
  <p>And this button press opens a new window in the webpage, which looks like this: <a href="https://i.stack.imgur.com/wwKL8.png" rel="nofollow noreferrer">Image of form after click</a></p>
  <p>Again, I have tried to pass a filepath here, but it does not seem to be keyboard addressable. As a user interacting with this form I can either drag and drop a file, or click the button to open windows File Explorer. The second option is what the code below does.</p>
  <pre><code>attach = driver.find_element_by_xpath(&quot;//div[@class='fsp-drop-area']&quot;)
  attach.click()
  </code></pre>
  <p>And now I am left with this: <a href="https://i.stack.imgur.com/dPEWm.png" rel="nofollow noreferrer">Image of form with windows explorer open</a> and I am unable to interact with it from python. I cannot seem to address it to find out what the name of the file search box at the bottom is, and I cannot send key strokes to it despite the file name search bar being highlighted when it opens. Earlier in the script I saved the photo I am now trying to upload, so I know its full filepath and could search for it if I can just access that box. I have not tried doing it graphically because this code will be put on a couple computers, and they do not have the same displays.</p>
  <p>Any help would be very welcome.</p>