简体   繁体   中英

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.

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!

一位同事刚刚发现它在 C# 中运行良好:

Driver.Instance.Manage().Window.FullScreen(); 
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!

这应该适合你:

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

您可以使用以下方法最大化窗口:

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

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);

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