Webdriver-Java-执行动作后如何释放键 [英] Webdriver - java - how to release keys after performing an action

查看:129
本文介绍了Webdriver-Java-执行动作后如何释放键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用网络驱动程序操作以执行一些按键组合:

I am using a webdriver Action to perform some keys combinations:

new Actions(getWebDriver()).sendKeys(Keys.CONTROL, ..).perform();

我的问题是Keys.CONTROL在执行操作后仍然保持激活状态.在单击几次之后,我的浏览器上新打开了一个选项卡,由于该键仍处于激活状态,因此出现了奇怪的行为.如何释放钥匙?谢谢.

My problem is that the Keys.CONTROL remains activated after the action is performed. And after some new clicks, I have new opened tabs on my browser and strange behaviors due to fact that the key is still activated. How to release the key? Thanks.

推荐答案

建立一系列动作,然后执行它们.关于如何释放控制键的一个有用的演示是通过模拟 Control +/按键来删除附加栏,然后随后发送keyUp消息以释放锁定键. Control 键:

Build up a series of actions and then perform them. A useful demonstration of how to release the control key is to remove the Add-on bar by simulating a Control+/ keypress then subsequently sending a keyUp message to release the held Control key:

WebDriver driver = getDriver();
String handle = driver.getWindowHandle();

// Remove the "add-on" bar.
driver.switchTo().defaultContent();
Actions actions = new Actions( driver );
actions
  .sendKeys( Keys.CONTROL, Keys.DIVIDE )
  .keyUp( Keys.CONTROL )
  .build()
  .perform();

// Return back to whatever window was first selected.
driver.switchTo().window( handle );

这篇关于Webdriver-Java-执行动作后如何释放键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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