Pergunta

I want to send the keys Ctrl and zero using Selenium WebDriver APIs

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

Foi útil?

Solução

Both these work for me:

A nice WebDriver approach

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

and the pure Java approach working on a higher level:

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

Outras dicas

You need to use unicode characters , I guess this will work -

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top