Problems when I tried to maximize window with Firefox 7 and webdriver 2.8

916 views
Skip to first unread message

Moises Siles

unread,
Oct 7, 2011, 5:05:04 PM10/7/11
to webd...@googlegroups.com

Hello guys,

I'm using the following code to maximize my window

((IJavaScriptExecutor)webDriver).ExecuteScript("if (window.screen){window.moveTo(0, 0);window.resizeTo(window.screen.availWidth,window.screen.availHeight);};");

That code was working fine under FF 3.6 and Firefox 6 and webdriver 2.7

Today I updated the dlls to 2.8 and also I updated my browser to firefox 7

After that my code to maximize the window is not working, I didn't get errors when the js is executed..... is there other way to achieve that.

Regards

Luke Inman-Semerau

unread,
Oct 7, 2011, 10:18:46 PM10/7/11
to webd...@googlegroups.com
Appears that FF7 doesn't allow window.resizeTo nor window.moveTo ... 

Looks like you should be able to override it with the setting "dom.disable_window_move_resize" ... but true and false both act the same for me (win7)... bug in FF7?


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Moises Siles

unread,
Oct 8, 2011, 2:34:11 AM10/8/11
to webd...@googlegroups.com
mmmm, I think I didn't get it :S

Where should I put this "dom.disable_window_move_resize"

Kfir Harel

unread,
Oct 9, 2011, 9:06:34 AM10/9/11
to webd...@googlegroups.com
Hi,
I'm having exactly the same problem.
Any suggestion?

Thanks

Luke Inman-Semerau

unread,
Oct 9, 2011, 2:24:41 PM10/9/11
to webd...@googlegroups.com
It's in about:config 

There's a way to set it on startup, I think with a FirefoxProfile. 

I was just trying manually with no success. 

-Luke

Luke Inman-Semerau

unread,
Oct 12, 2011, 4:33:29 PM10/12/11
to webd...@googlegroups.com
Ok... I think figured this one out...


You are no longer allowed to resize the "main" window in firefox7.

Here's a potential work around, I'll write it in python everyone else can translate:

from selenium import webdriver

driver = webdriver.Firefox()
handles = set(driver.window_handles)
driver.execute_script("window.open('about:blank');")
driver.switch_to_window((set(driver.window_handles) - x).pop())
driver.execute_script("window.resizeTo(500, 500);") # or whatever you want to do, like resize to the max

Kfir Harel

unread,
Oct 13, 2011, 9:41:36 AM10/13/11
to webd...@googlegroups.com
Thanks Luke!
Can someone translate to Java please?

Krishnan Mahadevan

unread,
Oct 13, 2011, 9:47:27 AM10/13/11
to webd...@googlegroups.com

    public void maximize(){

        String script = "if (window.screen){window.moveTo(0, 0);window.resizeTo(window.screen.availWidth,window.screen.availHeight);};";

        ((JavascriptExecutor) driver).executeScript(script);

    }

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Cléuber José

unread,
Oct 13, 2011, 12:01:10 PM10/13/11
to webd...@googlegroups.com
Hi,

Thank you
Krishnan Mahadevan, was behind this solution to a time


Thank you very much



2011/10/13 Krishnan Mahadevan <krishnan.ma...@gmail.com>



--
Att.
    Cléuber José
    http://www.cleuberjose.com/

Kfir Harel

unread,
Oct 14, 2011, 11:51:44 AM10/14/11
to webd...@googlegroups.com
Hi Krishnan,

I'm afraid this won't work anymore.
As Luke wrote: "You are no longer allowed to resize the "main" window in firefox7"
I'm looking for a Java translation of Luke's perl code solution

Thanks

Luke Inman-Semerau

unread,
Oct 14, 2011, 3:08:18 PM10/14/11
to webd...@googlegroups.com
Adapting Krishnan's solution for the FF7 issue, in Java it would become:

public void maximize(){

  Set<String> handles = driver.getWindowHandles();
  String script = "if (window.screen){var win = window.open(window.location); win.moveTo(0,0);win.resizeTo(window.screen.availWidth,window.screen.availHeight);};";
  ((JavascriptExecutor) driver).executeScript(script);
  Set<String> newHandles = driver.getWindowHandles();
  newHandles.removeAll(handles);
  driver.switchTo().window(newHandles.iterator().next());

}


P.S. the original code was Python (not Perl)

Moises Siles

unread,
Oct 14, 2011, 6:22:11 PM10/14/11
to webd...@googlegroups.com
Hi Luke

I'm trying to do that in C#, but I don't understand what you mean with Set<String> handles = driver.getWindowHandles();

Regards

Luke Inman-Semerau

unread,
Oct 14, 2011, 6:34:54 PM10/14/11
to webd...@googlegroups.com
The C# equivalent line is (somewhere close to):

ReadOnlyCollection<string> handles = driver.WindowHandles;

Moises Siles

unread,
Oct 14, 2011, 7:23:10 PM10/14/11
to webd...@googlegroups.com
Thanks, I think I found it......

System.Collections.ObjectModel.ReadOnlyCollection<string> handles = webDriver.WindowHandles;

Now I'm dealing with the 
removeAll and the iterator

I can't found those methods

:S

Anthony Kim

unread,
Oct 20, 2011, 11:38:49 PM10/20/11
to webd...@googlegroups.com
When I execute your method I receive two Firefox browser windows.  Can you please tell me why?  My code is below:

FirefoxProfile profile= new FirefoxProfile();
profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(profile);
maximize();

Luke Inman-Semerau

unread,
Oct 21, 2011, 4:18:10 AM10/21/11
to webd...@googlegroups.com
You are getting two windows because the bug is the main (first) window is not allowed to be resized in FF7. So the work-around is to popup a new window and resize it. That code switches to the new window so you can just continue your test as normal, just be sure to call driver.quit() at the end to close all windows :)

-Luke

sabf

unread,
Oct 24, 2011, 7:03:53 AM10/24/11
to webd...@googlegroups.com
is there a plan to fix the "problem" with two browsers?

Moises Siles

unread,
Oct 24, 2011, 1:41:19 PM10/24/11
to webd...@googlegroups.com
I think the problem is not related to webdriver, I think Luke said in one of the previous email that this is a FF issue

On Mon, Oct 24, 2011 at 1:03 AM, sabf <s.a...@gmx.de> wrote:
is there a plan to fix the "problem" with two browsers?

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/Flb_iA-pv84J.
Reply all
Reply to author
Forward
0 new messages