How To Maximize The Window In Selenium
In this tutorial, you will acquire how to maximize, minimize or resize the browser using selenium Webdriver. Explained through different scenarios using maximize() method and dimensions for resizing the browser.
Here is what we cover:
- Why Maximize a Browser in Selenium Automation?
- How to Maximize Window in Selenium
- Example: Resize a browser using selenium spider web driver
- Instance: Maximize a browser window using web commuter.
- Example: Minimize a browser window using web driver.
Why Maximize a Browser in Selenium Automation?
Elements on the web application may not be recognized past the selenium if the browser is not maximized and thereby making framework fail. Hence, Maximize the browser is very of import part of selenium framework. It is expert practice to maximize the browser while automating whatever web application. When the user executes the selenium framework or whatsoever script, browser may non exist in the total screen state and you lot need to maximize the browser using window maximize in Selenium to view all the elements of the web application. It is skillful to maximize the browser at the start of the script, and then that the script gets executed successfully without whatever error.
How to Maximize Window in Selenium
Here is how to maximize browser in Selenium:
To maximize browser in Selenium, y'all need to call the maximize() Selenium command to maximize window interface of the driver class.
void maximize() – This method is used to maximize the current browser.
Yous can customize the size of the browser according to the requirement of the scenario. Selenium webdriver does not provide any method for minimizing the browser, there is no such straight method. You need to utilize resize method to minimize the browser.
void setSize() – This method is used to gear up the size of the electric current browser. Dimension getSize() – This method is used to get the size of the browser in elevation and width. Information technology returns the dimension of the browser. Point setPosition() – This method is used to fix the position of the current browser.
Example: Resize a browser using selenium web commuter
a) Selenium script with explanation.
Script Description : In the below Selenium script shown the resize of the browser using testNG framework , steps of the scenario are :
- Open up the chrome browser .
- Launch the site .
- Wait for a few seconds as to view the resize action .
- Close the browser.
import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Resize { public static void principal(String args[]) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.go("https://www.guru99.com/"); Dimension d = new Dimension(300,1080); //Resize electric current window to the set dimension driver.manage().window().setSize(d); //To Delay execution for 10 sec. every bit to view the resize browser Thread.slumber(10000); //Close the browser driver.quit(); } }
b) Output Analysis
Opened the chrome browser , resized the browser, expect for a few seconds and closed the browser.
Instance: Maximize a browser window using web commuter.
a) Selenium script with explanation.
Script Clarification : In the below maximize in Selenium script shown, the maximization of the browser using testNG framework, steps of the scenario for maximize window Selenium are :
- Open up the chrome browser .
- Launch the site .
- Expect for a few seconds equally to view the browser maximize in Selenium activity .
- Close the browser.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Maximize { public static void main(String args[]) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","East://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.become("https://www.guru99.com/"); //Resize current window to the set dimension commuter.manage().window().maximize(); //To Delay execution for ten sec. as to view the maximize browser Thread.slumber(10000); //Shut the browser driver.quit(); } }
b) Output Assay
Opened the chrome browser , maximized the browser, expect for a few seconds and closed the browser.
Case: Minimize a browser window using web driver.
a) Selenium script with explanation.
Script Clarification : In the beneath Selenium script shown the minimize of the browser using testNG framework , steps of the scenario are :
- Open up the chrome browser .
- Launch the site .
- Expect for a few seconds as to view the minimize action .
- Close the browser.
import org.openqa.selenium.Signal; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Minimize { public static void main(Cord args[]) throws InterruptedException { WebDriver driver; Arrangement.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.get("https://www.guru99.com/"); Indicate p = new Point(0,3000); //Minimize the electric current window to the set position driver.manage().window().setPosition(p); //To Delay execution for ten sec. as to view the minimize browser //you can view in the taskbar below of the screen. Thread.sleep(10000); //Close the browser driver.quit(); } }
Note: If the user wants to use Firefox browser, and then user needs to gear up property of FirefoxDriver and create FirefoxDriver object instead of ChromeDriver in all higher up three scenarios scripts as given beneath:
System.setProperty("webdriver.gecko.commuter","East://Selenium//Selenium_Jars//geckodriver.exe "); driver= new FirefoxDriver();
b) Output Assay
Opened the chrome browser , minimized the browser, expect for a few seconds and airtight the browser.
TroubleShooting
- Utilize the latest versions of Selenium Jars, chromedriver, marionette driver and IEdriver etc.
- Cheque the compatibility of the selenium jars and browser used.
Summary
- In the in a higher place tutorial , nosotros illustrate the resizing of the browser through dissimilar scenarios like to maximize, minimize and resize as required in the project framework for dissimilar functionality.
- In the starting time scenario , we accept shown the resize of the browser in selenium.
Dimension d = new Dimension(300,1080); driver.manage().window().setSize(d);
- In the 2d scenario, we have shown the Selenium maximize window of the browser.
driver.manage().window().maximize();
- In the third scenario, we accept shown the minimize of the browser in selenium.
Point p = new Point(0,3000); commuter.manage().window().setPosition(p);
Source: https://www.guru99.com/maximize-resize-minimize-browser-selenium.html
Posted by: fullerseethe79.blogspot.com
0 Response to "How To Maximize The Window In Selenium"
Post a Comment