1

How can I run exe file using selenium webdriver. If i can run the exe file then i can automate the windows window using auto it tool and can run those exe using java selenium. it would help in browsing the file in Selenium

2 Answers 2

3

Yes, you can do that.

Runtime.getRuntime().exec("path to the autoIt exe file");

Ex:

Runtime.getRuntime().exec("E:\\Softwares\\Testing\\FileIUploadAutoit.exe");

Here is the small example of uploading a file to website using Selenium WebDriver java using TestNG

public class autoitclass {

 public WebDriver driver;


@BeforeTest 
public void websitemain()
{
    System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\Testing\\geckodriver.exe");

    driver = new FirefoxDriver();   


    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    String URL = "http://www.megafileupload.com/";

    driver.get(URL);
}

@Test
public void uploadFile() throws Throwable{

    driver.findElement(By.xpath(".//a[contains(@class,'slider-btn')]")).click();        
    driver.findElement(By.xpath(".//*[@id='initialUploadSection']")).click();
    Runtime.getRuntime().exec("E:\\Softwares\\Testing\\FileIUploadAutoit.exe");


}

@AfterTest
public void quit(){

    driver.quit();

}
Sign up to request clarification or add additional context in comments.

Comments

0

You cannot test standalone apps(desktop) using selenium(Some me please correct me if incorrect),exception being apps developed using Electron. When you compile and build an electron project you get an Exe which selenium can interact and test. The following example demo how to interact :

 public void TestSampleGooglePlayElectronApp()
        {
            ChromeOptions chromeOptions = new ChromeOptions();            
            chromeOptions.BinaryLocation = @"C:\MySampleElectronApp\MyApp.exe";           
            DesiredCapabilities capability = new DesiredCapabilities();
            capability.SetCapability(CapabilityType.BrowserName, "Chrome");
            capability.SetCapability("chromeOptions", chromeOptions);
            IWebDriver driver = new ChromeDriver(chromeOptions);            
            driver.FindElement(By.XPath("//paper-button[contains(text(),'Sign in')]")).Click();
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.