用于文件上载的自动代码在selenium中不起作用.Windows在进入路径后消失

问题描述 投票:0回答:2

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

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

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

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

我尝试通过更改第4行发送(“{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上运行

eclipse selenium autoit
2个回答
0
投票

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

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

0
投票

我有一个建议,不要使用来自autoit的exe。你可以使用java或python来使用autoit库。

以下是带autoit的java示例:

File file = new File("lib", "jacob-1.15-M4-x64.dll"); //path to the jacob dll
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
String notepad = "Untitled - Notepad";
String testString = "this is a test.";
x.run("notepad.exe");
x.winActivate(notepad);
x.winWaitActive(notepad);
x.send(testString);
Assert.assertTrue(x.winExists(notepad, testString));
x.winClose(notepad, testString);
x.winWaitActive("Notepad");
x.send("{ALT}n");
Assert.assertFalse(x.winExists(notepad, testString));

有关设置,您可以参考以下链接:

https://www.joecolantonio.com/selenium-autoit/

如果你想将python与autoit和selenium一起使用,你可以很容易地实现我在博客下面写的:

http://jbanshpal.blogspot.com/2018/02/first-basic-setup-and-example.html

如果有帮助,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.