代码之家  ›  专栏  ›  技术社区  ›  Apzal Bahin

用于文件上载的Autoit代码在selenium中不起作用。输入路径后,Windows将消失

  •  0
  • Apzal Bahin  · 技术社区  · 6 年前

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

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

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

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

    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文件,就应该上传该文件,但是窗口消失,没有文件被上传

    2 回复  |  直到 6 年前
        1
  •  0
  •   Jitendra Banshpal    6 年前

    嗨,试着跑你的 filesend.exe 使用提升的权限(例如Admin)

    Runtime.exec("runas /user:adminUser filesend.exe"); 
    
        2
  •  0
  •   marc_s HarisH Sharma    5 年前

    下面是使用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

    如果有帮助,请告诉我。