使用 AutoIt 通过 Selenium WebDriver 中的窗口提示上传文件 [英] Upload file via window prompt in Selenium WebDriver using AutoIt

查看:33
本文介绍了使用 AutoIt 通过 Selenium WebDriver 中的窗口提示上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Selenium WebDriver 中使用 AutoIt 上传文件.我有 AutoIt 代码,用于在窗口提示中粘贴文件路径并单击打开按钮.

I wanted to upload the file using AutoIt in Selenium WebDriver. I've AutoIt code for pasting the path of the file in window prompt and clicking on the open button.

但我的问题是在使用下面的代码点击浏览"按钮后,出现文件上传的窗口提示,我的代码没有从那个点移动到下一行,我调用 autoit 可执行文件.

but my problem is after clicking on the 'Browse' button using the below code, window prompt for file upload is appearing and my code is not moving from that point to next line where Im calling autoit executable file.

driver.findElement(By.xpath("//div[@class='field-group file-inputlist']//div[@class='field-group ']//input")).click();

我的 AutoIt 代码是

My AutoIt Code is

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 甚至没有抛出任何错误或异常.代码在浏览器单击浏览"按钮并打开窗口提示时停止.

Eclipse is not even throwing any error or exception. Code stops at the point where the browser clicks on Browse button and a window prompt opens.

注意:如果我手动关闭窗口提示,则代码将从那里继续.

Note: If I close the Window Prompt Manually then the Code is continued from there.

推荐答案

文件上传要遵循的步骤是:

Steps to be followed for File Upload are:

  1. 点击浏览按钮
  2. 等待窗口打开
  3. 等待窗口激活(可编辑)
  4. 设置控制&然后选择要上传的文件

尝试步骤 2 - 4 的示例代码

try sample code for step 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]")

这篇关于使用 AutoIt 通过 Selenium WebDriver 中的窗口提示上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆