[英]Selenium WebDriver - unable to upload file with AutoIT
I'm unable to upload file with AutoIT v3 我无法使用AutoIT v3上传文件
try with many ways, but no luck to get it work 尝试很多方法,但是没有运气能使它工作
method one: ( get Element is not currently visible
) 方法一:(
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: ( get Element is not currently visible
) 方法二:(
get Element is not currently visible
)
driver.findElement(By.name("fileName")).click();
Runtime.getRuntime().exec("D:\\Documentation\\Script To Upload File.exe");
method three: ( PASSED: testCaseOne, but no file is uploaded
) 方法三:(
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 对于附加链接,当我使用
firepath
检查时,它将引用具有1个匹配节点的xpath "html/body/input"
here my html file 这是我的html文件
<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;"/>
Here's the html code for the document upload section: 这是文档上传部分的html代码:
<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 脚本上传File.au3代码
; 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");
EDIT : Share the solution with those needed in future 编辑 :与将来需要的解决方案共享
this code not working (not sure why) 此代码不起作用(不确定原因)
driver.findElement(By.id("button2")).sendKeys("D:\\Documentation\\uploadFile.xls");
but in this way, it work 但是这样就可以了
driver.findElement(By.id("button2")).click();
driver.findElement(By.xpath("//input[@type='file']")).sendKeys("D:\\Documentation\\uploadFile.xls");
The type of the input control is file and therefore, using the below line to upload a file should work. 输入控件的类型是文件,因此,使用下面的行上载文件应该可以。
WebElement e = driver.findElement(By.id("the id"));
e.sendKeys("file path");
That is because in your Html file input type = file. 那是因为在您的HTML文件中, 输入类型= file。 if your input type is something else you will need to try with AutoIt or RobotApi.
如果您的输入类型是其他类型,则需要尝试使用AutoIt或RobotApi。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.