Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用selenium和AutoIT从windows explore自动上载图像_Selenium_Autoit - Fatal编程技术网

使用selenium和AutoIT从windows explore自动上载图像

使用selenium和AutoIT从windows explore自动上载图像,selenium,autoit,Selenium,Autoit,我必须使用Selenium自动化一个场景,比如从windows资源管理器将图像上载到TinyMCE组件。因为Selenium不支持操作系统控制,所以我使用AutoIt上传图像。 AutiIt将图像路径设置为“文件名”,似乎它也单击了“打开”按钮。但是图像没有加载到我的“源”字段 以下是我的Selenium命令: Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe"); // Path of the Auto

我必须使用Selenium自动化一个场景,比如从windows资源管理器将图像上载到TinyMCE组件。因为Selenium不支持操作系统控制,所以我使用AutoIt上传图像。 AutiIt将图像路径设置为“文件名”,似乎它也单击了“打开”按钮。但是图像没有加载到我的“源”字段

以下是我的Selenium命令:

Runtime.getRuntime().exec("C:/XXXXX/src/test/resources/uploadImage.exe");
// Path of the AutoIT script file
自动IT脚本:

WinActivate("Open")
Send("C:\LCNGProjects\Screenshots\Images\GifImage1.gif")
Sleep(5000)
Send("{ENTER}")
请参阅随附的屏幕截图


不确定我的问题是否正确,你是否编译了脚本

您可以通过下面的链接进行脚本编译,并逐步了解如何上传文件


您不需要使用AutoIt。自动将使您的脚本仅在windows计算机上可靠

而不是使用upload按钮的定位器(即xpath)查找元素,该按钮的标签为
type=“file”
。现在,将图像在计算机中的绝对路径传递给此简单的sendKeys,如下所示:-

button2.sendKeys("C:\\UsersDesktop\\logo\\Summit-Logo-900px.png");
或使用

System.getProperty("user.dir")); 
附加文件路径,将项目路径和文件名排除在项目中 例如:-

button.sendKeys(System.getProperty("user.dir")+"\\logo\\Summit-Logo-900px.png");
下面的链接包含更多上传文件的选项,如下所示:-

  • 使用SendKeys命令
  • 使用AutoIt脚本
  • 使用com接口


希望它能帮助您:)

我不打算在这里添加完整的源代码。您可以在测试用例中使用此命令调用AutoIT脚本

// Call to AutoIT script to upload the image

Runtime.getRuntime().exec("C:\\xxxxx\\src\\test\\resources\\uploadImage.exe");
自动IT票据

 ControlFocus("Open","","Edit1")
    ControlSetText("Open","","Edit1","C:\xxxx\Images\jpgImage")
    ControlClick("Open","","Button1")
有关更多信息,请参阅以下链接