How To Set/Get Window Position And Size In Selenium WebDriver

Sometimes you lot request to set window position in addition to size or get window size and position In selenium software test. Selenium webdriver software testing tool has many useful methods using which nosotros tin play amongst spider web browser window for dissimilar purpose. One of them Is window().maximize(); which nosotros occupation In each in addition to every
webdriver software exam to maximizing the window. Same way, webdriver has window size in addition to seat related Independent methods.

What Is window size in addition to position?
Before learning how to set/get size in addition to position, We request to empathize It.
  • Window size agency tiptop in addition to width of window.
  • Window seat agency distance of window from left side(X Coordinates) of covert in addition to piece of work past times side(Y Coordinates) of screen.
Bellow given Image describes you lot to a greater extent than close window size in addition to position.

window().setSize() to ready window size
We tin use window().setSize() method to ready the size of window In selenium webdriver software test. We tin ready window width to 300 in addition to tiptop to 500 dimensions using bellow given syntax In selenium webdriver.
driver.manage().window().setSize(new Dimension(300,500));

window().getSize() to acquire window size
We tin use window().getSize() method to acquire size of window.
Bellow given syntax volition provide window tiptop using getSize().getHeight().
driver.manage().window().getSize().getHeight()

Bellow given syntax volition provide window width using getSize().getWidth().
driver.manage().window().getSize().getWidth()

window().setPosition() to ready seat of window
We tin ready window seat to l points from left side in addition to 200 points from piece of work past times side using bellow given syntax.
driver.manage().window().setPosition(new Point(50,200));

window().getPosition() to acquire seat of window
Use window().getPosition().getX() to acquire window seat from left side equally bellow.
driver.manage().window().getPosition().getX()

To acquire window seat from piece of work past times side of screen, occupation window().getPosition().getY() In your software exam equally bellow.
driver.manage().window().getPosition().getY()

Full webdriver exam to explore all inwards a higher house methods of webdriver window Is equally bellow.

package Testing_Pack;  import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace course of report WindowSizePosition {  WebDriver driver;  @BeforeTest  populace void setup() throws Exception {   driver = novel FirefoxDriver();   driver.manage().window().maximize();  }    @Test(priority=1)  populace void setGetWinSize(){   //WebDriver setSize method used to ready window size width = 300 in addition to tiptop = 500.   driver.manage().window().setSize(new Dimension(300,500));      //WebDriver getSize method used to acquire window width in addition to height.   System.out.println("Window tiptop Is -> "+driver.manage().window().getSize().getHeight());   System.out.println("Window width Is -> "+driver.manage().window().getSize().getWidth());  }    @Test(priority=2)  populace void setGetWinPosition(){   //WebDriver setPosition method used to ready window seat x coordinate = l in addition to y coordinate = 100.   driver.manage().window().setPosition(new Point(50,200));      //WebDriver getPosition method used to acquire window seat x,y coordinates.   System.out.println("Window seat X coordinates Is -> "+driver.manage().window().getPosition().getX());   System.out.println("Window seat Y coordinates Is -> "+driver.manage().window().getPosition().getY());  } }

This way you lot tin re-size/set seat of your webdriver window during exam execution.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post