trevellyon
trevellyon

Reputation: 113

Unable to sendkeys using webdriverjs specifically F11 to maximise the browser

With the below code block it opens a chrome browser fine it just won't full screen the browser using F11. i used to use C# and selenium and that worked fine using this method on chrome and different browsers. It finds the element 'body' but then does not send the key press. Am I doing something wrong here that i should be requiring some other library?

the documentation for webdriverjs is pathetic and there is very few examples, I am seriously considering dumping it for something else possibly python.

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.chrome()).
    build();
driver.get('https://www.google.co.uk/');

driver.wait(function () {
    return driver.getTitle().then(function (title) {
        return title === 'Google';
    });
}, 1000);


driver.findElement(webdriver.By.xpath('/html/body')).sendKeys("F11");

why are we doing this. we are developing a website that will change depending on size 800x600 + with and without the toolbar depending on how the screen is used different items will be displayed. i can maximise the window using,

driver.manage().window().maximize();

This however still leaves the toolbar present and doesn't act as if the user has pressed the F11 key.

Upvotes: 5

Views: 9466

Answers (6)

Lorenzo Sciuto
Lorenzo Sciuto

Reputation: 1685

For me the one emulating correctly the F11 on startup is:

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);

Or if the kiosk mode is preferred:

ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);

Upvotes: 1

Lord PK
Lord PK

Reputation: 19

A co-worker has just discovered that it works well in C# with:

Driver.Instance.Manage().Window.FullScreen(); 

Upvotes: 2

Andre989
Andre989

Reputation: 74

it tooks some time to find it but you should have all the Keys in webdriver.Key

driver.findElement(webdriver.By.xpath('/html/body')).sendKeys(webdriver.Key.F11);

Hope it helps!

Upvotes: 4

sam2426679
sam2426679

Reputation: 3847

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).send_keys(Keys.F11).perform()

I use a similar command to toggle JS via Firefox's NoScript add-on

edit: I just tested, and it works!

Upvotes: 1

user3179064
user3179064

Reputation:

You can maximise the window using:

driver.manage().window().maximize();

Upvotes: 0

Richard
Richard

Reputation: 9019

This should work for you:

driver.findElement(webdriver.By.xpath('/html/body')).sendKeys(Keys.F11);

Upvotes: 0

Related Questions