无法使用AutoIT脚本上传文件 [英] Not able to upload a file using AutoIT script

查看:119
本文介绍了无法使用AutoIT脚本上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此进行了彻底的搜索,但徒劳无功.我的问题是我编写了AutoIT脚本,当它在C#或Java代码之外执行时,它可以完美地工作.脚本是:

I have searched thoroughly on this but in vain. My issue is I have written the AutoIT script which works perfectly when its executed outside the C# or Java code. The script is:

WinWaitActive(文件上传")发送("C:\ Users \ faris \ Desktop \ RP1.jpg")睡眠(2000)ControlFocus(文件上传",","Button1")发送("{Enter}")

我确保我的代码正在调用相同的脚本.在程序中执行此脚本后,将打开文件上传"对话框,我可以看到文件路径也显示在文件名"字段中.但随后对话框将退出,并且文件未上传.从技术上讲,不会单击对话框上的打开"按钮.现在,我尝试使用控制点击"命令,但它是相同的.我也尝试了所有类型的Waits,但没有用.我对此并不陌生,非常感谢任何帮助.

I made sure that my code is calling the same exact script. When this script is executed in the program, The 'File Upload' dialog box opens up, I can see the file path is also displayed in the 'File name' field. but then the dialog box just quits and the file is not uploaded. technically the 'Open' button on the dialog box is not being clicked. Now, I have tried using the 'Control Click' command but its just the same. I have also tried every type of Waits but its of no use. I am new to this and would really appreciate any kind of help.

这是代码示例:

IWebElement browse  = driver.FindElement(By.Id("browse"));
        browse.SendKeys(Keys.Enter);
        Thread.Sleep(2000);
Process.Start("C:\\Users\\faris\\Desktop\\Autoit2.exe");

浏览"是上传文件"按钮,发送"Enter"键会在Firefox中调用文件上传"对话框.

"Browse" is the 'Upload file' button and sending an 'Enter' key invokes File upload dialog box in Firefox.

推荐答案

好的,那么我是如何找到自己的解决方案的.我仍然不知道是什么原因导致了故障.我在代码中两次执行了AutoIT脚本.第一次对话框打开并如上所述退出,但是第二次执行脚本时,文件成功上传.

Okay, So some how I found the solution my self. I still don't know what is causing the failure. The way its working is I executed the AutoIT script 2 times in my code. The first time dialog opens up and quits as mentioned above but the second time the script is executed the file gets uploaded successfully.

这篇关于无法使用AutoIT脚本上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆