In this post, I will demonstrate how to use manage().window().maximize() command in Selenium 3, for maximizing the Browser window.
Prerequisite:
Before using the manage().window().maximize() command with Selenium 3, we have to first create a Java project and configure that with Selenium 3 and chrome driver. Please go through the below link for the same:
- Click here to configure the Java project with Selenium 3 and chrome driver.
- Also install the latest version of Chrome Browser in your machine.
Once the above configuration is done, go through the below steps for executing manage().window().maximize() command in Selenium 3 for maximizing the browser window:
1. Create a Java class file under 'src' and create a new class say 'Demo' as shown below:
2. Write the three lines of code shown in the screen-shot in which the first line will set the path to chromedriver.exe file, the second line will open the chrome browser and the third line will open the Web Application in the Browser:
3. Now, lets write the code which uses manage().window().maximize() of Selenium WebDriver for maximizing the Chrome Browser window as shown below:
4. Click on the 'Save All' button to save the so far written code as shown below:
5. Right click on the newly created Java Class and select to Run As > Java Application as shown below:
6. Observe that the latest version of Chrome Browser will be launched by default in non-maximized mode, later the application URL will be opened in the browser and finally the Browser will be maximized as shown below:
Conclusion:
manage().window().maximize() command needs to be used in Selenium 3 for maximizing the Browser window.
No comments:
Post a Comment