[英]How to press “ALT+S” in Selenium WebDriver using Java
I need to Send ALT+S
Key event using Selenium Web Driver for an ``EditBox. 我需要使用Selenium Web Driver为``EditBox发送
ALT+S
Key事件。 Cursor Position is already set to EditBox I am using following code 光标位置已设置为EditBox我正在使用以下代码
driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.ALT+"S"))
but it's not giving me desired result. 但它没有给我想要的结果。 It's Typing character
'S'
in the Edit Box. 它是在编辑框中键入字符
'S'
。 I have tried another code but got the same result. 我尝试了另一个代码,但得到了相同的结果。
Actions action =new Actions(driver);
action.keyDown(Keys.ALT).sendKeys(String.valueOf('\u0053')).perform();
Thanks in Advance 提前致谢
I want to Add one more thing here. 我想在这里再补充一点。 The code is working Properly in Firefox 12 but its not working properly in IE9
代码在Firefox 12中正常运行,但在IE9中无法正常运行
Cross-browser issues are rather hard to investigate as they are specific to particular driver and not WebDriver API. 跨浏览器问题很难调查,因为它们特定于特定驱动程序而不是WebDriver API。
Another variant that might work. 另一种可能有效的变体。
driver.findElement(By.xpath("your editbox's XPath")).sendKeys(Keys.chord(Keys.ALT, "s"));
As workaround I might recommend to take a look to AutoIT ( Official site ) or Robot ( Java Doc ) 作为解决方法,我可能会建议您查看AutoIT( 官方网站 )或Robot( Java Doc )
Try this. 尝试这个。 It might work, I haven't tried though
它可能会奏效,但我没试过
driver.findElement(By.xpath("your editbox's XPath"))
.sendKeys(Keys.chord(Keys.ALT + Keys.S));
You can achieve this by using Robot class of java 你可以通过使用Robot的java类来实现这一点
try{
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_ALT);
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_S);
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.