Srivardhan
Srivardhan

Reputation: 104

Click() does not complete

Steps

  1. Click on the Browse button in Firefox
  2. Opens a window dialogue (Browse for a file)
  3. Choose the file (AutoIt script)

Java code

    driver.findElement(By.xpath("")).click();
    String path = "C:\\FileUpload.Av3.exe";
    driver.findElement(By.xpath (")).click(); - Browse Button in Web application

    try {
          Runtime.getRuntime().exec(path); - Execute AutoIT .exe file
    } catch (IOException e) {
          e.printStackTrace();
    }

Working

  1. Put a breakpoint in line 2 of the Java code and
  2. comment line 3 and
  3. click on Browse button and
  4. continue execution after clicking manually

This works fine with AutoIt.

Not working

After line 3 the execution will not continue and the controls are not passed back from Firefox to Selenium.

Upvotes: 1

Views: 2028

Answers (4)

bbbco
bbbco

Reputation: 1540

Selenium WebDriver cannot handle it. Use sendKeys to insert the local path to the file in the File Input element:

String path = "C:\FileUpload.Av3.exe";
driver.findElement(By.xpath("/path/to/the/file/input/element")).sendKeys(path);

Please see FAQ docs of Selenium WebDriver.

Upvotes: 4

Deolas
Deolas

Reputation: 372

I also got the same issue after clicking on "Download Excel" link. To fix this issue, I used JavascriptExecutor to get execution control back.

js.executeScript("arguments[0].click();", button); 

Upvotes: 0

Nathan Dace
Nathan Dace

Reputation: 1555

The Click call is a blocking call, which does not return until the page is loaded. Since the click opens a dialog box, the click will not return until the dialog box is closed.

To get around this, call Click in a seperate thread, and then call the AutoIt script. Once the AutoIt script closes the dialog box, the click will return, and the rest of your test can continue.

Upvotes: 0

HemChe
HemChe

Reputation: 2337

Remove try-catch block and use only the below code. Let me know if it is working.

driver.findElement(By.xpath("")).click();
driver.findElement(By.xpath (")).click(); - Browse Button in Web application
String path = "C:\\FileUpload.Av3.exe";
Runtime.getRuntime().exec(path); - Execute AutoIT .exe file

Upvotes: 0

Related Questions