首页 > 解决方案 > 文件上传的自动代码在 selenium 中不起作用。输入路径后 Windows 消失

问题描述

在 Eclipse 中运行 Autoit 代码时,我遇到了一个奇怪的问题。

我在编译以下代码以在弹出窗口中上传文本文件后创建了一个 exe 文件

如果我在窗口屏幕处于活动状态的命令提示符下手动运行此 exe 文件,则该文件已成功上传到应用程序

如果我通过eclipse运行相同的exe代码我可以看到按钮被按下并且窗口消失(并且没有上传文件)

我尝试将第 4 行更改为 send("{ENTER}") 仍然没有运气

1.WinWaitActive("Open") //Open is the  window name 
2.Send("C:\Users\AB\Desktop\sampleupload.txt",@SW_SHOWNORMAL) //this works in eclipse
3.WinWaitActive("Open")//this works
4.ControlClick("Open","","Button1") //Button clicked correctly

Runtime.getRuntime().exec("filesend.exe")//code used in eclipse to run the autoit exe file

执行 exe 文件后应该上传文件,但是窗口消失并且没有上传文件。问题仅在通过 eclipse 运行时发生

标签: eclipseseleniumautoit

解决方案


嗨尝试filesend.exe使用提升的权限运行您(例如管理员)

Runtime.exec("runas /user:adminUser filesend.exe"); 

推荐阅读