over 8 years ago
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:
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);
}
}
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);
}
}
Can you help out the community by solving one of the following Automation problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)