简体   繁体   中英

how to open a new empty tab in firefox using selenium and java

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.

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