Search code examples
pythonseleniumtkinterwxpythonselenium-chromedriver

How do I handle the system windows with Python on Windows OS?


With Selenium Webdriver, I have to upload some files on a website but since the pop-up window for browsing the file location is handled by the operating system and not the browser, I cannot automate that part with Selenium.

So I want to know which framework or module I need to use to work with system windows of Windows OS. Can tkInter or wxPython be used for this?

My script will be used on Windows 7, 8 & 10.


Solution

  • Actually, you can upload files without interacting with upload prompt pop-ups.

    To be able to handle file upload with selenium you should send path to file to appropriate input field without clicking on "Upload" button. Try following:

    path_to_file = 'C:\\Files\\path\\to\\file'  # use your specific path instead
    driver.find_element_by_xpath('//input[@type="file"]').send_keys(path_to_file)
    

    P.S. Let me know if this code doesn't work as you expect