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.
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.
SeleniumDemo.java
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.
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(new Point(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.SeleniumDemo.java
package demoPackage; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class SeleniumDemo { public static WebDriver driver; public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Launching the chrome driver "); // Set the chrome driver exe file path System.setProperty("webdriver.chrome.driver","E:\\selenium_sumit\\chromedriver_win32_2.33\\chromedriver.exe"); // Instantiate the chrome driver driver = new ChromeDriver(); // set the browser URL in get() to load the webpage driver.get("https://google.com/"); //WebDriver used to set window position x coordinate = 100 and y coordinate = 200. driver.manage().window().setPosition(new Point(100,200)); //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()); } }
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.
No comments:
Post a Comment