Selenium Actions还是Java AWT机器人? [英] Selenium Actions or Java AWT Robot?

查看:119
本文介绍了Selenium Actions还是Java AWT机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到现在,我已经使用Selenium Actions库来在自动化项目中执行鼠标/键盘操作.

Until now I have used the Selenium Actions library in order to perform mouse/keyboard actions in our automation project.

最近,我发现了Java AWT Robot类.它与Selenium Actions库有什么可比性?在其中一个案例中是否存在一些其他案例可以解决的极端情况?限制?稳定?性能方面的考虑?

Recently, I have discovered the Java AWT Robot class. How is it comparable to Selenium Actions library? Is there some corner-cases in one of them that the other solve? restrictions? stability? performance considerations?

推荐答案

这些工具的工作方式存在巨大差异. Selenium使用WebDriver API并将命令发送到浏览器以执行操作(通过"JSON有线协议").

There is a huge difference in terms of how do these tools work. Selenium uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").

Java AWT Robot使用本机系统事件来控制鼠标和键盘.

Java AWT Robot uses native system events to control the mouse and keyboard.

如果要进行浏览器自动化,理想情况下,您永远不要使用Robot之类的东西,因为通常selenium提供的功能已绰绰有余.不过,在某些情况下会打开浏览器或本机OS弹出窗口,例如,上传/下载文件-这也可以通过机器人 解决-尽管通常会有硒-有助于避免使用Robot的特定解决方案/解决方法.这些变通办法的关键思想是因为我们无法控制弹出窗口,所以才不要打开它们".

If you are doing browser automation, ideally, you don't ever use things like Robot since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot - though usually there are selenium-specific solutions/workarounds that can help avoiding using Robot. The key idea of these workarounds is "since we cannot control the popups, just don't let them to be opened".

例如,当您在Firefox中下载文件时,会出现一个文件浏览器弹出窗口,提示您选择位置和文件名.这是使用selenium无法操作的.但是,您可以做的是,让Firefox知道哪些文件类型以及要自动保存下载的位置,而不显示弹出窗口.请参阅在Firefox中访问文件下载对话框.

For example, when you download a file in Firefox, you are getting a file browser popup suggesting you to choose a location and filename. This is something you cannot manipulate with using selenium. But, what you can do , is let Firefox know which file types and where do you want to save downloads automatically, without showing the popup. See Access to file download dialog in Firefox.

相关主题:

  • Java AWT Robot | Selenium Uses
  • Selenium WebDriver and HTML Window location by using Java
  • One solution for File Upload using Java Robot API with Selenium WebDriver by Java
  • Use of Robot Class In Selenium WebDriver For Automation Purpose

这篇关于Selenium Actions还是Java AWT机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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