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

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

问题描述

我想在Selenium WebDriver中使用AutoIt上传文件。我有AutoIt代码用于在窗口提示符中粘贴文件的路径,然后点击打开的按钮。



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

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

我的自动代码是

  WinWait([CLASS:#32770],,10); 

//使用WinWait
ControlFocus(文件上传,,Edit1)返回的句柄将输入焦点设置为上传窗口的编辑控件Sleep(2000);

//在编辑字段上设置文件名文本
ControlSetText(文件上传,,编辑1,$ CmdLine [1])睡眠(2000);

//点击打开按钮
ControlClick(文件上传,,Button1);

Eclipse甚至不会抛出任何错误或异常。代码停止在浏览器点击浏览按钮的位置,并且打开窗口提示。



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

解决方案

文件上传的步骤如下:


  1. 单击浏览按钮

  2. 等待窗口打开

  3. 等待窗口处于活动状态(可编辑)

  4. 设置控制&然后选择要上传的文件

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



WinActivate(文件上传)
$$$ $ $ $ ControlSetText(File Upload,,[CLASS:Edit; INSTANCE:1],$ CmdLine [1])$ ​​b $ b; ControlSetText(Choose,,[CLASS:Edit; INSTANCE: 1],*****绝对文件路径********)
ControlClick(文件上传,,[类:按钮;文本&打开] )


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.

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();

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 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. Click on Browse button
  2. Wait for Window to open
  3. Wait for the window to be active(editable)
  4. Set control & then choose file to upload

try sample code for step 2 - 4

Sample code:

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天全站免登陆