Selenium webdriver – unable to upload file with AutoIT

I’m unable to upload file with AutoIT v3

try with many ways, but no luck to get it work

method one: (result get Element is not currently visible)


driver.findElement(By.xpath("//input[@type='file']")).click();

Runtime.getRuntime().exec("D:\\Documentation\\Script To Upload File.exe");

method two: (result get Element is not currently visible)


driver.findElement(By.name("fileName")).click();

Runtime.getRuntime().exec("D:\\Documentation\\Script To Upload File.exe");

method three: (result PASSED: testCaseOne, but NO file is uploaded)


driver.findElement(By.id("button2")).click();

Runtime.getRuntime().exec("D:\\Documentation\\Script To Upload File.exe");

For the attach link, when I inspect with the firepath, it will refer to xpath "html/body/input" with 1 matching node

here my html file


<input type="file" name="fileName" style="position: absolute; margin: -5px 0px 0px -175px; padding: 0px; width: 220px; height: 30px; font-size: 14px; opacity: 0; cursor: pointer; display: none; z-index: 2147483583; top: 457px; left: 459px;"/>

also in my html file, attach file attributes


<html>

<body>

<div>

<div>

<form>

<div>

<dl>

<dd class="attachFile">

<div class="attachUpload">

<a id="button2" class=" ">

<img class="attachIco" alt="" src="http://qa.seleniumqa.com/ga/en/clean/images/BLANK.GIF"/>

Attach file

</a>

</div>

</dd>

</dl>

</div>

</form>

</div>

</div>

</body>

</html>

Script To Upload File.au3 code


; It will wait for 8 seconds to appear File Upload dialog.

; Used Title property of File upload dialog window.
WinWait("File Upload","",8)
; Set control focus to File name Input box of File Upload dialog.

; Used Class property of File upload dialog window and Class+Instance property for File name Input box.
ControlFocus("[CLASS:#32770]","","Edit1")
Sleep(3000)
; Set the name of file In File name Edit1 field.

; "Test.txt" file Is located In AutoIT folder of E drive. So we have to provide full path like E:\AutoIT\Test.txt.
ControlSetText("[CLASS:#32770]", "", "Edit1", "D:\Documentation\uploadFile.xls")
Sleep(3000)
; Click on the Open button of File Upload dialog.
ControlClick("[CLASS:#32770]", "","Button1");

Add Comment
1 Answer(s)
Best answer

I solved the problem with code below

 driver.findElement(By.id("button2")).click();
 driver.findElement(By.xpath("//input[@type='file']")).sendKeys("D:\\Documentation\\uploadFile.xls");
 
nexuschristo Train Answered on May 15, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.