Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't maximize chrome window using Selenium

I've tried to maximize the window onPreapre by the command below:

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

But it doesn't maxmize the window and there's no error on selenium webdriver logs, actually it seems like the execute has been succeed -

Starting ChromeDriver 2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6) on port 5814
Only local connections are allowed.
17:14:28.898 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome, chromeOptions={args=[--no-sandbox, --test-type, --memory-metrics, --console, --crash-on-failure], prefs={download={directory_upgrade=true, default_directory=./Users/Idan/automation/tests/downloaded/, prompt_for_download=false}}}}]]
17:14:28.909 INFO - Executing: [set script timeout: 90000])
17:14:28.910 INFO - Done: [set script timeout: 90000]
17:14:28.969 INFO - Executing: [maximise window])
17:14:29.236 INFO - Done: [maximise window]
17:14:29.244 INFO - Executing: [maximise window])
17:14:29.250 INFO - Done: [maximise window]
like image 627
Idan E Avatar asked Jan 07 '17 15:01

Idan E


People also ask

How do I make Chrome full screen in Selenium?

Use --start-fullscreen argument to Specify the browser should start in fullscreen mode, like if the user had pressed F11 right after startup.

How do you maximize a window in Selenium?

To maximize browser in Selenium, you need to call the maximize() Selenium command to maximize window interface of the driver class. void maximize() – This method is used to maximize the current browser.


3 Answers

You can try it with start-maximized flag:

capabilities: {
  'browserName': 'chrome',
  'chromeOptions': {
    'args': ['start-maximized']
  }
}
like image 96
Priyanshu Shekhar Avatar answered Oct 11 '22 20:10

Priyanshu Shekhar


I remember we had a similar issue - what we did is first set the size of the window and then maximize - don't remember exactly why did we apply this workaround, but it works for us:

browser.manage().window().setSize(1400, 900);
browser.manage().window().maximize();
like image 37
alecxe Avatar answered Oct 11 '22 18:10

alecxe


According to your log - you do maximization twice. Maybe the first time it is maximized, and after the second try it is restored down to default size

like image 37
user3618181 Avatar answered Oct 11 '22 20:10

user3618181