How To Set/Get Window Position And Size In Selenium Web Driver:
Sometimes you need to set window position and size or get window size and position in selenium software test. Selenium web driver software testing tool has many useful methods using which we can play with web browser window for different purpose. One of them Is window().maximize(); which we use In each and every
web driver software test to maximizing the window. Same way, web driver has window size and position related independent methods.
Set Size:
We can use window().setSize() method to set the size of window In selenium webdriver software test.
Get Size:
We can use window().getSize() method to get size of window.
Example:
package com.rameshsoft.rameshselenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SetWindowDimension {
public
static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\ramesh\\Desktop\\java\\desk\\geckodriver-v0.11.1-win64\\geckodriver.exe");
WebDriver
driver=new FirefoxDriver();
int
hight=driver.manage().window().getSize().height;
int
width=driver.manage().window().getSize().width;
System.out.println("Hight
:"+hight);
System.out.println("Width
:"+width);
driver.manage().window().setSize(new
Dimension(520, 460));
driver.manage().timeouts().implicitlyWait(55,TimeUnit.SECONDS);
driver.manage().deleteAllCookies();
driver.navigate().to("https://www.gmail.com");
Thread.sleep(2000);
driver.quit();
}
}
No comments:
Post a Comment