16

I am trying send a shortcut with Actions.sendKeys, but it isn't working.

(New Actions(driver)).SendKeys(Keys.ALT, Keys.SHIFT, "z");
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Volkov Pavel
  • 195
  • 1
  • 2
  • 5

5 Answers5

18

You can check this question to refer about this - Pressing Ctrl+A in Selenium WebDriver

Check the answer which uses the chord method. In your case, you can do this -

String selectAll = Keys.chord(Keys.ALT, Keys.SHIFT,"z");
driver.findElement(By.tagName("html")).sendKeys(selectAll);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hari Reddy
  • 3,808
  • 4
  • 33
  • 42
7

This can also be done using Actions keyUp and keyDown functions.

WebDriver driver = new FirefoxDriver();
Actions keyAction = new Actions(driver);
keyAction.keyDown(Keys.ALT).keyDown(Keys.SHIFT).sendKeys("z").keyUp(Keys.ALT).keyUp(Keys.SHIFT).perform();
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Revanth Kumar
  • 809
  • 12
  • 18
0

Try it:

SendKeys.SendWait("%+z")
Dmitry
  • 1
  • 1
0

Assuming you're using JavaScript,

Keys.chord(keys)

Also, the documentation is at https://www.selenium.dev/documentation/en/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
asciidude
  • 272
  • 1
  • 3
  • 19
0

Apart from the Keys.chord(Keys.ALT, Keys.SHIFT,"z"); method as suggested in the other/accepted answer, I would suggest you try the Robot framework for using keyboard shortcuts.

You can do something like;

Robot robot = new Robot();
Thread.sleep(1000);
robot.delay(3000);


robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_Y);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_Y);

I guess this would help sort your problem.

IAmMilinPatel
  • 413
  • 1
  • 11
  • 19