Tuesday, March 13, 2018

How To Set Browser Window Position In Selenium Webdriver

Today, we are going to discuss how to set browser window position in selenium webdriver. Window position means distance of window from left side(X Coordinates) of screen and top side(Y Coordinates) of screen. To set the browser window position, we are using setPosition() method of selenium webdriver.

Code snippet to set browser window position using selenium webdriver :
Specify the X and Y coordinate details in setPosition method.

//WebDriver used to set window position x coordinate = 100 and y coordinate = 200.
driver.manage().window().setPosition(newPoint(100,200));

Code snippet to get the X and Y of browser window position using selenium webdriver :
This will help you to get the X and Y coordinate position of browser window.

//WebDriver used to get window position x,y coordinates.System.out.println("Window position X coordinates Is -> "+driver.manage().window().getPosition().getX());System.out.println("Window position Y coordinates Is -> "+driver.manage().window().getPosition().getY());

Set the browser window position in selenium webdriver :

Lets see the example of webdriver script, which will help you to set the browser window position during the time of script execution.

This is all about setting the browser window position in selenium during the run time. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.