1
votes

Using the controlFocus method:

ControlFocus("File Upload", "", "Edit1")
ControlSetText("File Upload", "", "Edit1", "C:\Test.2.0.war")
ControlClick("File Upload", "", "Button1"

AutoIt successfully browsed and opened a file in Firefox and the correct file name was displayed, however; the Selenium webdriver was unable to click on the upload button after this, throwing an error:

UnreachableBrowserException: Error communicating with the remote browser.

The webdriver code used is:

Runtime.getRuntime().exec("D:\\AutoIT\\FileUpload.exe");
Thread.sleep(5000);

What could possibly be wrong?

2
There's no need to use Autoit, File upload is supported by Selenium by calling sendKeys on the web element <input type=file>. - Florent B.
Sendkeys doent work in all cases. For this project, it worked in chrome but not in Firefox. Firefox disabled the upload button after the file path was browsed and opened. AutoIT fixed that problem - user7123229
It's possible to upload a file with Firefox, but depending on the version of the browser and driver you may need to apply a workaround with executeScript to either display the <input> or to trigger the change event. - Florent B.

2 Answers

2
votes

A major cause of this issue is multiple gecko drivers running in the background. To resolve: go to the task manager (Ctrl + Alt + Delete), in the processes tab, under background processes, terminate all the gecko driver instances and rerun webdriver. This worked for me, eliminating the UnreachableBrowserException: Error communicating with the remote browser error

0
votes

To add to @AutoQA nice answer, Better yet take care of closing instances using driver.dispose() in a finally clause (or in @AfterClass), or make a script to end those instances with something like (for Windows):

taskkill /F /IM geckodriver.exe