The following code works. That is, the action is the same as pressing Ctrl + A.

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"a"); 

This also works:

 driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.CONTROL,"a")); 

But this code does not want to work either (nothing happens, just the execution ends):

 driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t"); 

this also does not work

 driver.findElement(By.tagName("body")).sendKeys(Keys.chord(Keys.CONTROL,"n")); 

Why does it work with "a", but not with t / n? I need to open new tabs and new windows. I tried all the various examples from the Internet, I don’t want to work.

    1 answer 1

    It was possible to solve this:

     try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_T); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_T); } catch (AWTException e) { e.printStackTrace(); }