简体   繁体   中英

How to open a new tab using an extension and selenium?

how can I press a combination of buttons using selenium in chrome? I have an extension which opens a new tab by pressing control + shift + x but how can I use the shortcut of this extension in selenium? I have tested many things but they didnt work for me.

Thx for every answer:)

Try the following code:

It send series of key codes to the body element of the webpage.

driver.findElement(By.tagName("body")).sendKeys(Keys.LEFT_CONTROL, Keys.LEFT_SHIFT, "x");

Alternative is Actions

Actions builder = new Actions(driver);
Action seriesOfActions = builder
        .keyDown(Keys.LEFT_CONTROL)
        .keyDown(Keys.LEFT_SHIFT)
        .sendKeys("x")
        .build();

seriesOfActions.perform();

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