Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Selenium Webdriver - Set browser width and height

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 420
    Comment on it

    Here, we discuss that how to resize the browser's width and height in Selenium WebDriver. It allows to resize and also maximize the window from its API. In this, Dimension Class helps to resize and declare the object by initializing the width and height.

     

    Also, we need to import:


    'import org.openqa.selenium.Dimension'

     

     

    Steps to be automated:

     

    • Launch the browser
    • Open your site
    • Navigate to your required location
    • Resize the browser width and height

     

     

    WebDriver Code goes as below:

     

    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.Dimension;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class ResizeWindow {
    
    	public static void main(String[] args) throws InterruptedException {
    		
            WebDriver driver = new FirefoxDriver();
    		
            driver.get("http://google.com");
            
    		driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
    		driver.manage().window().maximize();
    		
    		WebElement textField = driver.findElement(By.xpath(".//*[@id='sb_ifc0']"));
    		textField.click();
    		textField.sendKeys("testing");
    		
    		driver.findElement(By.xpath(".//*[@id='sblsbb']/button")).click();
    		
    		Thread.sleep(3000);
    		
            System.out.println(driver.manage().window().getSize());
    		Dimension d = new Dimension(420,600);
    		
    		driver.manage().window().setSize(d);System.out.println(driver.manage().window().getSize());
    		
    		Dimension d1 = new Dimension(520,700);
    		driver.manage().window().setSize(d1);
    
    	}
    
    }
    

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: