I've tried this:
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
But it doesn't add any new tab.
Also tried this:
((JavascriptExecutor) driver).executeScript("window.open();");
But it opens a new window instead of using the same one.
How can I do this?
I think it would be easier to use the Robot
class.
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(Exception e) { }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.