简体   繁体   English

Selenium 2.41.0 WebDriver与Java机器人一起使用

[英]Selenium 2.41.0 webdriver working with Java robot

I have just upgraded selenium from 2.37.1 to 2.40.0 and have come across an issue. 我刚将硒从2.37.1升级到2.40.0,遇到了一个问题。

I am using selenium webdriver to run tests in a project. 我正在使用Selenium Webdriver在项目中运行测试。 A page is using a plupload that opens an uploader window, which I have been automating in my selenium with a Java robot. 一个页面正在使用plupload打开一个上载器窗口,我一直在使用Java机器人在selenium中对其进行自动化。

Since upgrading to 2.40.0 though when it gets to the plupload the webdriver just hangs until the i manually close the upload window and then the robot will start it's commands. 自从升级到2.40.0以来,尽管到了plupload,Webdriver一直挂起,直到i手动关闭上传窗口,然后机器人将启动它的命令。

This was not an issue with 2.37.1. 对于2.37.1,这不是问题。 Has anyone come across the same problem and have a fix? 有谁遇到过同样的问题并已解决? Is there any other way to handle upload windows with the webdriver? 还有其他方法可以使用网络驱动程序来处理上传窗口吗?

Thanks. 谢谢。

You can do the same using following types of code: 您可以使用以下类型的代码执行相同的操作:

Type 1: Using sendKeys command 类型1:使用sendKeys命令

WebElement upload = driver.findElement(By.id("upload"));            
upload.sendKeys("path of your file");

Type 2: Using Java Robot class 类型2:使用Java Robot类

WebElement upload = driver.findElement(By.id("upload"));    
upload.click();   

setClipboardData("path of your file");

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(5000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM