selenium - 如何在不使用 selenium java 中的发送键的情况下通过双击自动上传文件?
问题描述
尝试使用以下代码自动化但不工作
动作动作=新动作(驱动程序);
fileupoladbtn.sendKeys(System.getProperty("user.dir") +"/Images/zoom_out.jpg");
actions.dragAndDrop(fileupoladbtn, fileupoladbtn1);
解决方案
我可以从您简短描述的问题中了解到,您需要与 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)
更多细节
推荐阅读
- azure - 为什么我的同意管理员权限请求要求所有权限?
- python - 如果不在条件内,程序将永远运行
- c# - 如何在不为每种情况使用 if 和 switch 语句的情况下重构链中的数百个条件?
- python - AWS Elastic Inference,Tensorflow 2 - 加速器没有变量支持,退出
- python - Python - 如果我增加列表的大小,为什么我的 for 循环的长度函数不会改变
- c# - 数据库和数据集中日期时间格式的区别
- design-principles - 谁首先创建了 WET 原则?
- react-native - 如何使用 Asyncstorage 在第二个屏幕上保存和查看 JSON 数据?
- java - HttpURLConnection vs Volley 或 Retrofit
- netlogo - Tick Reporter 进行品种颜色转换