Search code examples
selenium-webdriverselenium-chromedriverautoit

Handle browser dialog window without focus


I have a Selenium WebDriver based script to automate file uploading. It uploads list of files one by one. I use AutoIT script to handle dialog window, file chooser window. Parameter $CmdLine[1] contains the path of actual file.

ControlFocus("Open a file","","Edit1")
ControlSetText("Open a file","","Edit1", $CmdLine[1])
ControlClick("Open a file","","Button1")

I execute it from Java code as following:

Runtime.getRuntime().exec(autoITExecutable);

It opens dialog window, so it can't work without focus on browser window.

File upload field works like this demo: https://encodable.com/uploaddemo/


Solution

  • I ran simple script for the link you gave and it works great

    import os
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    
    driver.get("https://encodable.com/uploaddemo/")
    
    driver.find_element_by_name("uploadname1").send_keys(os.getcwd() + "/test.csv")
    
    driver.find_element_by_name("email_address").send_keys("none@getnada.com")
    driver.find_element_by_name("first_name").send_keys("Tarun")
    driver.find_element_by_id("uploadbutton").click()
    

    uploaded