简体   繁体   English

如何使用Selenium WebDriver按Ctrl + 0(零)

[英]How to press Ctrl+0 (Zero) using Selenium WebDriver

I want to send the keys Ctrl and zero using Selenium WebDriver APIs 我想使用Selenium WebDriver API发送键Ctrl和零

I tried the below code but not working 我尝试了以下代码,但无法正常工作

 Actions action = new Actions(driver);
        action.keyDown(Keys.CONTROL).sendKeys("F000").keyUp(Keys.CONTROL).perform();

Looking for help 寻求帮助

Both these work for me: 这些对我都有效:

A nice WebDriver approach 不错的WebDriver方法

String ctrlZero = Keys.chord(Keys.CONTROL, "0");
driver.findElement(By.tagName("html")).sendKeys(ctrlZero);

and the pure Java approach working on a higher level: 以及纯Java方法在更高层次上起作用:

Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_0);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_0);

You need to use unicode characters , I guess this will work - 您需要使用Unicode字符,我想这可以工作-

You must make this change in your code - 您必须在代码中进行此更改-

Actions action =new Actions(driver);
    action.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0030')).perform();

Let me know if are facing any problems after this change.You can check the unicode table here - http://unicode.org/charts/PDF/U0000.pdf 让我知道如果都面临这个change.You后的任何问题都可以在这里查询Unicode的表- http://unicode.org/charts/PDF/U0000.pdf

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

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