首页 > 解决方案 > 如何在不使用 selenium java 中的发送键的情况下通过双击自动上传文件?

问题描述

尝试使用以下代码自动化但不工作

动作动作=新动作(驱动程序);

fileupoladbtn.sendKeys(System.getProperty("user.dir") +"/Images/zoom_out.jpg");

actions.dragAndDrop(fileupoladbtn, fileupoladbtn1);

标签: seleniumselenium-webdriveruploaddropzone.js

解决方案


我可以从您简短描述的问题中了解到,您需要与 selenium 不处理的 windows 文件上传进行交互,您需要使用 auto it scrip 并在您的 selenium 脚本中调用它。您可以下载 Auto it 和 SCiTE 这是编辑。

下面是自动文件上传脚本 -

Sleep(1000)
ControlFocus("Open","","Edit1")
Sleep(2000)
Send("{Enter}")
Sleep(1000)
Send("{Backspace}")
Sleep(1000)
Send($CmdLine[1])
Send("{Enter}")
Sleep(2)
ControlClick("Open","","Button1")

当您转到工具并在 autoit 编辑器中编译时,它将被保存,请注意此处的名称。

一旦完成弹出文件上传的操作,文件上传的窗口处理程序在脚本上方可见调用。

对于 Java

Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");

对于 Python

subprocess.Popen('C:\\Handle\\FileUpload.exe '+File_path, shell=True)

更多细节

https://www.autoitscript.com/site/autoit/downloads/

https://www.guru99.com/use-autoit-selenium.html


推荐阅读