how to maxmize window in selenium webdriver ?

448 views
Skip to first unread message

jiteshwar nishad

unread,
Oct 10, 2012, 2:18:52 AM10/10/12
to seleniu...@googlegroups.com
hi all ,
i am trying to execute these code but its not working.
*****************************************************************************************************************************************

package testing;

import java.io.File;

import jxl.Sheet;
import jxl.Workbook;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.thoughtworks.selenium.SeleneseTestCase;

public class for_loop extends  SeleneseTestCase {
    private String inputFile;

    public void setInputFile(String inputFile) {
        this.inputFile = inputFile;
       
    }
    @Before
    public void setUp() throws Exception {
        WebDriver driver = new FirefoxDriver();
        String baseUrl = "http://www.facebook.com/";
        selenium = new WebDriverBackedSelenium(driver, baseUrl);
    }
   
    @Test
    public void testUntitled() throws Exception {
       
        setInputFile("D:\\traning material\\my work template\\facebook.xls");
        File inputWorkbook = new File(inputFile);
        Workbook w;
        w = Workbook.getWorkbook(inputWorkbook);
        // Get the first sheet
        Sheet sheet = w.getSheet(0);
        System.out.println("I got a label " + sheet.getCell(0,0).getContents());
       
        selenium.open("http://www.facebook.com/");
        selenium.windowMaximize();
       
       
        Thread.sleep(5000l)   ;
       
      //  selenium.windowFocus();
   //   selenium.windowMaximize();
       
        assertEquals("Welcome to Facebook - Log In, Sign Up or Learn More",selenium.getTitle());
        System.out.println(selenium.getTitle());
       
         Thread.sleep(5000l)   ;
        
        
        
       
       
       
       
       
       
    }
   
    @After
    public void tearDown() throws Exception {
        //selenium.stop();
    }

}


thanks ,
regards ,
jitesh

raghu nandan

unread,
Oct 10, 2012, 2:39:22 AM10/10/12
to seleniu...@googlegroups.com
I am not sure
In RC the below will do job,may be we can find something similar in webdriver also
selenium.getEval("window.resizeTo(1024, 768); window.moveTo(100,100);");



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ffcVxYFXHmQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
with regards
RaghuNandan

Do you know that it takes 10 litres of water to produce 1 sheet of A4 paper?

Don't print this unless you have to :)

 



UmaMahesh

unread,
Oct 10, 2012, 2:52:28 AM10/10/12
to seleniu...@googlegroups.com
//selenium.windowMaximize();
//driver.manage().window().maximize();

if above 2 commands doesn't work try the below code.


driver.manage().window().setPosition(new Point(0,0));
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
driver.manage().window().setSize(dim);

Thanks
Uma Mahesh.
mahesh.......

jiteshwar nishad

unread,
Oct 10, 2012, 6:21:12 AM10/10/12
to seleniu...@googlegroups.com
Hi mahesh ,
thanks a ton
it works very well . thanks for replying .


regards ,
jitesh

jiteshwar nishad

unread,
Oct 10, 2012, 6:23:26 AM10/10/12
to seleniu...@googlegroups.com
hi RaghuNandan ,
thanks , for response , but actually that code is not working .

thanks for giving me feedback


regards
jitesh

syam

unread,
Oct 10, 2012, 6:36:19 AM10/10/12
to seleniu...@googlegroups.com
Hi Nishad,
  Use below code to maximize the browser

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

Thanks,
Syam..

jiteshwar nishad

unread,
Oct 11, 2012, 12:53:38 AM10/11/12
to seleniu...@googlegroups.com
hi Syam ,
that code i had tried before , but i was not working , thanks for response .


thanks
regards,
jitesh

Lukus

unread,
Nov 19, 2012, 2:40:47 PM11/19/12
to seleniu...@googlegroups.com
I have four methods for maximizing the window on linux/windows:

via Javascript: 
if (window.screen) {window.moveTo(0,0); window.resizeTo(window.screen.availWidth,window.screen.availHeight);} else window.resizeTo("+resolution.width+","+resolution.height+");

via Keystrokes:
if (OS_Name.equalsIgnoreCase("microsoft")){
 log
("Pressing ALT+SPACE then X for maximize");
 
//alt space x on windows maximizes
 
Robot robot = new Robot();
 robot
.keyPress(KeyEvent.VK_ALT);
 robot
.keyPress(KeyEvent.VK_SPACE);
 
 
//release opposite order
 robot
.keyRelease(KeyEvent.VK_SPACE);
 robot
.keyRelease(KeyEvent.VK_ALT);
 
 robot
.keyPress(KeyEvent.VK_X);
 robot
.keyRelease(KeyEvent.VK_X);
 
}
 
else if (OS_Name.equalsIgnoreCase("linux")){
 log
("Pressing ALT+F10 for maximize");
 
 
Robot robot = new Robot();
 robot
.keyPress(KeyEvent.VK_ALT);
 robot
.keyPress(KeyEvent.VK_F10);
 
 
//release opposite order
 robot
.keyRelease(KeyEvent.VK_F10);
 robot
.keyRelease(KeyEvent.VK_ALT);
 
 
}

via WebDriver:
driver.manage().window().maximize();

and via startup options (Chrome only)
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));

Then my logic for method for maximizing the window depending on the browser follows this logic:
if (Browser_Name.equalsIgnoreCase("internet explorer")){
   maximizeWindowViaJavascript
();
 
}
 
else if (Browser_Name.equalsIgnoreCase("chrome")){
   log
("Not maximizing window for Chrome since done via startup arguments... using keystrokes causes lockups.");
 
}
 
else if (Browser_Name.equalsIgnoreCase("firefox") && OS_Version.equalsIgnoreCase("windows 7 64-bit")){
   driver
.manage().window().maximize();
 
}
 
else{
   maximizeWindowViaKeyStrokes
();
 
}


So, in practice, the reality for me has been to test what actually works for each... the javascript method is consistent in my experience for IE, the keystroke method work consistently for almost all other browsers except Chrome and Firefox on Win7-64bit where the WebDriver method works.  However, the WebDriver method craps out on Windows 8, FYI.


For Macs, I use apple scripts to manage setting the window to frontmost and setting the size.

It be nice if there was one method that handled it all but my experience is to find out what works for each case and use that.

Good luck!

Gopal Krishna

unread,
Nov 19, 2012, 8:48:36 PM11/19/12
to seleniu...@googlegroups.com

yor need to mention the following windowMaximize() like

ex:      selenium.windowMaximize();



On Wed, Oct 10, 2012 at 11:48 AM, jiteshwar nishad <jites...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ffcVxYFXHmQJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
gopala krishna munagala
Reply all
Reply to author
Forward
0 new messages