Skip to content
This repository has been archived by the owner. It is now read-only.

Browser window control #174

Closed
lukeis opened this issue Mar 2, 2016 · 61 comments
Closed

Browser window control #174

lukeis opened this issue Mar 2, 2016 · 61 comments

Comments

@lukeis
Copy link
Member

@lukeis lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 174

It would be nice if we could maximise/ minimise/ resize browser window.


Reported by m.bukowski on 2009-03-19 15:00:02

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Doesn't the WebDriver fail to retreive elements when controlling window is minimized?
When System.out the result of the element.getValue() with controlling window closed,
the WebDriver does not generate output, however it successfully writes to it when the
window is opened. 

Reported by hanishi77 on 2009-07-29 08:49:06

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

More important would be possibility to maximize that you can take better screenshot
and see whole window.

Reported by m.bukowski on 2009-07-29 09:20:20

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

I think the issue above is true if the switchTo().frame() is iFrame.

Reported by hanishi77 on 2009-07-29 09:54:15

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Some options to potentially add:

WebDriver.resize(Dimension) - should this be on the browser window including all
Chrome, or on the display port? There are arguments to be had for both.  Accordingly,
perhaps justification for:

WebDriver.resizeWindow(Dimension) and WebDriver.resizeRenderArea(Dimension) perhaps?

Also, possibly adding launch sizes to constructors (though we have quite enough
constructors for some drivers as it is, so perhaps not)

Reported by dawagner on 2009-08-29 02:03:30

  • Status changed: Accepted
  • Labels added: Type-Enhancement, Browser-All, OpSys-All
  • Labels removed: Type-Defect

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

In fact, I'm going to try for (short of any decent reason against):

WebDriver.resizeTo(Dimension, [boolean includeChrome = true])

in the Java WebDriver in the next week or so

Reported by dawagner on 2009-08-29 09:16:57

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by dawagner on 2010-02-03 23:17:39

  • Labels added: Priority-Low
  • Labels removed: Priority-Medium

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Actually there is a larger problem with window handling:
1. Resizing;
2. Loosing window handle without throwing any meaningful exception: driver just
throws smth like ElementNotFound, while as in console I see native driver exceptions
regarding non-existing COM object. Usually this happens if application opens up
popups (other tabs or windows) or you manually close window. I can't handle in tests
this situation because it's hard to identify "lost window" issue in test;
3. Unable to force close of driver if some modal dialog is open or current window
handle is lost. That means that webdriver is not suitable for continous integration
tests due to no garantee to run tests multiple times. It just stucks on closing
window forever;
4. No ability to work with alerts is a big barrier. It is solved ugly and partially
with overriding javascript functions but doesn't solve issue with native browser
modal dialogs: file open dialog, confirmation to close window, etc. That means again
that webdriver is still not ready for continous integration.

Reported by ITPetra on 2010-03-06 07:58:09

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Another vote for this. I think this feature is very important.

It would be nicer if Selenium/WebDriver can simulate a user dragging a window to resize
it, to make sure no ill effects show up in the app

Reported by binod80 on 2010-10-18 20:01:27

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Resizing the browser window is possible with Javascript. Here's sample code in Python
using webdriver:

b = webdriver.Firefox()
#Resize the window to the screen width/height
b.execute_script('window.resizeTo(screen.width,screen.height)')
#Move the window to position 0,0
b.execute_script('window.moveTo(0,0)')



Reported by pdobrie%grammatech.com@gtempaccount.com on 2011-03-28 21:22:07

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Another vote for this. It is needed in order to take a better screenshot!

Reported by turturiellomartino on 2011-05-19 10:04:01

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Hello everyone

Firefox has an issue/feature where it will not load SWFs if the SWF area is not visible.
 To run our Firefox tests with our other browser tests in parallel on the same box,
we need a way to bring a window to front.

We've tried setting profile.setPreference("dom.disable_window_flip", false) and using
Javascript to execute "window.self.focus()", but this has no effect.  Seems like something
the WebDriver would have to do.

Thanks!
Jason

Reported by jason@bobberinteractive.com on 2011-05-24 20:41:14

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Issue 1750 has been merged into this issue.

Reported by dawagner on 2011-06-05 13:21:23

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

yep it would be very useful to have control of the browser window from the API. Using
javascript is a hack and can't do all window manipulations. I particularly miss a lot
the ability to toggle full-screen consistently on all browsers. 

Reported by stoyan.dimkov on 2011-06-05 13:35:01

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Hi all.

I have written code which extends Chrome, Firefox and Internet Explorer which creates
resizing functionality. It currently works through DesiredCapabilities and native code
(so I only have it working for Windows right now). Since this seems to be a popular
request, is it feasible/useful for me to submit this as a patch and have it integrated
into WebDriver?

JavaScript can be used to accurately resize viewports only in Firefox. Chrome will
simply not allow it if your window is running in a tab and Internet Explorer can not
do so reliably and accurately either (across all versions). For Windows it is also
easy to extend the changes I've made to allow maximizing and minimizing of the window.

Reported by michaelwskwan on 2011-07-11 15:22:05

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Patches are always welcomed with open arms. Please feel free to submit the code, and,
if you've not already done so, sign the CLA so we know it's okay for us to include
it in the project:

https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&formkey=dFFjXzBzM1VwekFlOWFWMjFFRjJMRFE6MQ#gid=0

Reported by simonstewart@google.com on 2011-07-22 15:46:40

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Any news on this?
I would also be interested in such functionality.
We need to have to test on browser windows with different sizes and using JavaScript
seems like a workaround to me.

Reported by pasci.bach on 2011-08-25 11:59:18

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Guys What's the situation with this ..... Its frustrating as webdriver 2.7 seems to
throw an elmenebt not visible sometimes if the button is present on the page but not
in full view

Reported by euston on 2011-10-06 09:45:14

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

eus...@gmail.com, if you experience a problem with elements visibility, please report
it as a separate issue, I doubt it is related to ability to resize|maximize browser
window.

Reported by barancev on 2011-10-06 09:48:29

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

It would be very useful for testing of certain applications if a way to open an IE window
in Kiosk mode could be added. Usually, an IE window can be opened in kiosk mode using
the "-k" command-line option. 

Using 'sendKeys(Keys.F11)' will open the browser full-screen without any toolbars as
per kiosk mode, however with no way to check if the browser is already maximised in
that way it can also accidentally take you out of full screen.

I'd suggest maybe putting something in under 'DesiredCapabilities' , similar to how
the Chrome WebDriver does it:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new ChromeDriver(capabilities); 

Reported by rockybst.DR on 2011-11-29 11:59:26

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@39: Please file that as an enhancement in a separate issue.

Reported by jari.bakken on 2011-11-29 15:25:04

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Filed a bug here: http://code.google.com/p/chromium/issues/detail?id=107630

Reported by kkania@chromium.org on 2011-12-14 23:48:39

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by dawagner on 2012-02-05 17:11:54

  • Labels added: GettingStarted

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

please add me to cc :)

Reported by Rajesh.huria on 2012-03-28 09:09:34

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@43: Star the issue in the upper left corner and you'll be notified of changes.

Reported by jari.bakken on 2012-03-28 09:10:47

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by dawagner on 2012-04-10 21:56:10

  • Labels added: GettingInvolved
  • Labels removed: GettingStarted

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@jari.bakken "@32: I just implemented this for Firefox."


Could you please let me know where this is documented or how do I achieve this with
Java driver? I wasn't able to find it

Reported by raviteja.bond007 on 2012-05-04 09:54:48

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@46:

driver.manage().window() returns an instance of WebDriver.Window:

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Window.html

Reported by jari.bakken on 2012-05-04 17:52:21

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

window.Maximize() does not work for Chrome yet.
Chrome version: 19.0.1854
Windows OS : 7
WebDriver version : 2.21

Reported by ravindrarupadhya on 2012-05-30 04:57:45

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@48: See if this helps I used the below Geb config:

/*
    This is the Geb configuration file.

    See: http://www.gebish.org/manual/current/configuration.html
*/

import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.remote.DesiredCapabilities

// Use htmlunit as the default
// See: http://code.google.com/p/selenium/wiki/HtmlUnitDriver
driver = { 
    def driver = new HtmlUnitDriver()
    driver.javascriptEnabled = true
    driver
}

environments {

    // run as "grails -Dgeb.env=chrome test-app"
    // See: http://code.google.com/p/selenium/wiki/ChromeDriver
    chrome {
        driver = {
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("chrome.switches", ["--start-maximized"]);
            new ChromeDriver(capabilities)
        }
    }

    // run as "grails -Dgeb.env=firefox test-app"
    // See: http://code.google.com/p/selenium/wiki/FirefoxDriver
    firefox {
        driver = {
            def driver = new FirefoxDriver()
            driver.manage().window().maximize()
            driver
        }
    }

    ie {
        driver = { new InternetExplorerDriver()}
    }
}

Reported by raviteja.bond007 on 2012-05-30 07:36:36

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by barancev on 2012-05-31 03:29:39

  • Labels removed: Browser-IE

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

I'm working on selenium webdriver(version-2.21.0),it would be great if i could know
whether there is any way to maximize opera browser for automation.

Reported by srividya.subramani@photoninfotech.net on 2012-06-07 06:56:06

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

This API has now been implemented in the browser drivers that are maintained by the
selenium project. The Chrome and Opera drivers are maintained by Google and Opera respectively.
This issue can now be closed.

Reported by simon.m.stewart on 2012-06-15 11:58:44

  • Status changed: Fixed

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

I'd like to see the Minimize() method as well, as the first request back in 2009.
Regards.

Reported by allanhmedeiros on 2014-05-12 13:12:54

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Hi guys,

I observed similar issue, In my case scripts are running fine, but when I am running
scripts through task scheduler, it is not able to click certain elements, when I saw
the screenshot I found browser window was not maximized so hiding certain items.

I do not understand WHY browser maximize command is not working when scripts running
through task scheduler? 

Thanks for help

Reported by ajay.baunthiyal@kaplan.com on 2014-06-05 08:17:01

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

We're facing similar issue when we run through a task scheduler. Chrome doesn't load
ChromeOptions with specified settings like 

options.addArguments("--window-size=1900,1000");
options.addArguments("--start-maximized");
it uses small resolution 1040x784, so tests fail. 

Is there any workaround for setting screen resolution? 

p.s. it didn't help too
                        driver().manage().window().maximize();
.driver().manage().window().setSize(new Dimension(1366, 768));

Reported by alex.golovko on 2015-01-22 17:41:04

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Hi,

The above same issue we are facing for chrome, Firefox, IE.
I tried below code then also it takes the resolution 1040*784

driver.manage().window().maximize();
driver.manage().window().setSize(new Dimension(1400, 768));

Any solutions is there to set the resolution to 1366 * 768?

Reported by Geowills234 on 2015-02-25 07:12:34

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by jari.bakken on 2015-02-25 08:22:14

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Hey guys,

To set the browser resolution, you first need to set the window position to the top
left corner and then re-size it to the desired resolution.

 driver.manage().window().setPosition(new Point(0, 0))
 driver.manage().window().setSize(new Dimension(1366 , 786))

Hope it helps.

Reported by piyush.ranjan@eltropy.com on 2015-04-09 15:53:44

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@piyushi.r... Thank you!

That works perfectly to avoid the same problem as mentioned above: setSize() stops
working as expected when running a suite of tests.

I was seeing windows that were supposed to open at 1200 wide start to appear at odd
widths like 917 wide after 4 or 5 tests had completed.

The setPosition call sorted that out completely!

Reported by RedYetiDave on 2015-04-11 07:49:59

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

I want code for selenium, which can make web browser minimized and out of focus so i
can work on any other thing while it is running..... 

Reported by dhruv110800116014 on 2015-08-05 06:24:44

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

i am using below code for Chrome:

driver.manage().window().setPosition(new Point(0, 0));
org.openqa.selenium.Dimension d = new org.openqa.selenium.Dimension(1900, 1900);
driver.manage().window().setSize(d);

And Chrome Resizes to 1900*1900 without any issues when i run it on local.

but when run via RemoteDriver on Selenium Grid the size i am getting is (1044, 788).

Any idea to setChrome Driver size more than 1044 on RemoteDriver on Selenium Grid would
be appreciated.

Reported by shnakey.garg on 2015-09-02 02:10:55

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Just a guess: Did you check the screen resolution on the remote system? You can't set
a window size bigger than screen resolution.

Reported by codecab.driver on 2015-09-03 09:35:23

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Yeah, very true. We changed the resolution and Chrome worked. 

PS: While we are at this when chrome was running as headless than chrome would not
listen to me but when we switched to headed version of chrome, it worked like charm.

Reported by shnakey.garg on 2015-09-03 12:04:18

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 17:47:53

  • Labels added: Restrict-AddIssueComment-Commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.