mouchin777
mouchin777

Reputation: 1588

Selenium how to press two different key combinations after starting up the browser

So im trying to load a website with node selenium, and when im at its root, just press two different key combinations, waiting a bit between each other.

So far ive gotten this

    const webdriver = require('selenium-webdriver');
    
    const Keys = webdriver.Key
    const By = webdriver.By
    
    const driver = new webdriver.Builder().
       withCapabilities(webdriver.Capabilities.firefox()).
       build();
    
       
    driver.get('https://example.com');
    
    //this element is supposed to be some almost root container, but ideally i dont want to select anything, just press the keys.
    
    driver.findElement(By.id('canvas-container')).sendKeys('webdriver', Keys.CTRL + Keys.F5);
driver.findElement(By.id('canvas-container')).sendKeys('webdriver', Keys.CTRL + Keys.F5);
//wait 2-5 sec
driver.findElement(By.id('canvas-container')).sendKeys('webdriver', Keys.CTRL + Keys.SHIFT + Keys.C);

That doesn't work because

Element is not reachable by keyboard

Can someone help with this?

Upvotes: 1

Views: 973

Answers (1)

Prophet
Prophet

Reputation: 33361

In case you don't want to select anything, just press the keys ActionSequence is what you are looking for!
I'm not really familiar with Selenium on node.js, but from what I have found the syntax is something like this:

let action = new webdriver.ActionSequence(driver);
    action.sendKeys(Keys.CTRL + Keys.F5);

action.perform()

Upvotes: 2

Related Questions