Java Selenium WebDriver-无法使用AutoIT上载文件

Java Selenium WebDriver-无法使用AutoIT上载文件,java,selenium,file-upload,selenium-webdriver,autoit,Java,Selenium,File Upload,Selenium Webdriver,Autoit,我无法使用AutoIT v3上载文件 尝试了很多方法,但都没有成功 方法一:(get元素当前不可见) 方法二:(get元素当前不可见) 方法三:(通过:testCaseOne,但没有上传任何文件) 对于附加链接,当我使用firepath检查时,它将引用xpath“html/body/input”,其中有一个匹配节点 这里是我的html文件 <input type="file" name="fileName" style="position: absolute; margin: -5px 0

我无法使用AutoIT v3上载文件

尝试了很多方法,但都没有成功

方法一:(
get元素当前不可见

方法二:(
get元素当前不可见

方法三:(
通过:testCaseOne,但没有上传任何文件

对于附加链接,当我使用
firepath
检查时,它将引用xpath
“html/body/input”
,其中有一个匹配节点

这里是我的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;"/>
编辑:与将来需要的人共享解决方案

此代码不工作(不确定原因)

但通过这种方式,它起作用了

driver.findElement(By.id("button2")).click();
driver.findElement(By.xpath("//input[@type='file']")).sendKeys("D:\\Documentation\\uploadFile.xls");

输入控件的类型是文件,因此,使用下面的行上载文件应该可以

WebElement e = driver.findElement(By.id("the id"));
e.sendKeys("file path");

这是因为在Html文件中输入类型=文件。如果输入类型是其他类型,则需要尝试使用AutoIt或RobotApi。

有什么问题?您不知道如何检查元素是否已加载?您好@yawang,文件未上载为什么不改用
Robot
?看到这个帖子-Hi@LittlePanda,我想我这里的问题更多的是无法点击上传链接触发对话框窗口。我已经在其他网站上测试了代码,AutoIT v3部分没有问题。大家好,再次@LittlePanda,我使用
Robot
进行了测试,但是使用
AutoIT 3
得到了相同的结果,没有上传任何文件。但是我用
Robot
&
AutoIT v3
用完全相同的代码上传了这个文件。谢谢你的帮助,不知道为什么
driver.findelelement(By.id(“button2”)).sendKeys(“D:\\Documentation\\uploadFile.xls”)不工作并且
驱动程序.findElement(By.id(“button2”))。单击()``driver.findElement(By.xpath(“//input[@type='file'])).sendKeys(“D:\\Documentatio‌​n\\uploadFile.xls”)是工作。Nvm,只要它起作用,对我来说没问题
<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;"/>
<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>
; 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");
driver.findElement(By.id("button2")).sendKeys("D:\\Documentation\\uploadFile.xls");
driver.findElement(By.id("button2")).click();
driver.findElement(By.xpath("//input[@type='file']")).sendKeys("D:\\Documentation\\uploadFile.xls");
WebElement e = driver.findElement(By.id("the id"));
e.sendKeys("file path");