How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

前端 未结 28 2029
悲&欢浪女
悲&欢浪女 2020-11-29 18:20

Is there any way to maximize the browser window using WebDriver (Selenium 2) with C#?

相关标签:
28条回答
  • 2020-11-29 18:43

    Through the below code i'm able to maximize the window,

    ((JavascriptExecutor) driver).executeScript("if(window.screen){
        window.moveTo(0, 0);
        window.resizeTo(window.screen.availWidth, window.screen.availHeight);
        };");
    
    0 讨论(0)
  • 2020-11-29 18:45

    I had the same problem, but the problem can be solved by using following code.

    driver.manage().window().fullscreen();
    
    0 讨论(0)
  • 2020-11-29 18:47

    There's an outstanding issue to add this functionality to WebDriver, which can be tracked here: http://code.google.com/p/selenium/issues/detail?id=174

    A workaround would be to use the JavascriptExector as follows:

    public void resizeTest() {
        driver.Navigate().GoToUrl("http://www.example.com/");
    ((IJavaScriptExecutor)driver).ExecuteScript("window.resizeTo(1024, 768);");
    }
    
    0 讨论(0)
  • 2020-11-29 18:48

    For Webdriverjs (node.js), the following maximizes chrome window.

    var webdriver = require('selenium-webdriver');
    var driver = new webdriver.Builder().
    withCapabilities(webdriver.Capabilities.chrome()).build();
    driver.manage().window().maximize();
    driver.get('hxxp://localhost:8888');
    
    0 讨论(0)
提交回复
热议问题