我想使用 Selenium WebDriver 中的 AutoIt 上传文件。我有 AutoIt 代码,用于在窗口提示中粘贴文件路径并单击打开按钮。
但我的问题是使用下面的代码单击“浏览”按钮后,出现文件上传的窗口提示,并且我的代码没有从该点移动到我调用 autoit 可执行文件的下一行。
driver.findElement(By.xpath("//div[@class='field-group file-inputlist']//div[@class='field-group ']//input")).click();
我的 AutoIt 代码是
WinWait("[CLASS:#32770]","",10) ;
//Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("File Upload","","Edit1") Sleep(2000) ;
//Set the File name text on the Edit field
ControlSetText("File Upload", "", "Edit1", $CmdLine[1]) Sleep(2000) ;
//Click on the Open button
ControlClick("File Upload", "","Button1");
Eclipse 甚至没有抛出任何错误或异常。代码在浏览器单击“浏览”按钮并打开窗口提示时停止。
注意:如果我手动关闭窗口提示,则代码将从那里继续。
最佳答案
文件上传应遵循的步骤是:
- 点击“浏览”按钮
- 等待窗口打开
- 等待窗口激活(可编辑)
- 设置控制并选择要上传的文件
尝试步骤 2 - 4 的示例代码
示例代码:
WinWait("File Upload")
WinActivate("File Upload")
ControlSetText("File Upload", "", "[CLASS:Edit;INSTANCE:1]",$CmdLine[1])
;ControlSetText("Choose", "", "[CLASS:Edit;INSTANCE:1]", "*****Absolute File Path********")
ControlClick("File Upload", "", "[CLASS:Button;TEXT:&Open]")
关于java - 使用 AutoIt 在 Selenium WebDriver 中通过窗口提示上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24837367/