TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Selenium

    window .maximize() , .close() and .quit()

    In this article we will see sample selenium webdriver programs to maximize window. Difference between .close() and quit() functions.

    Browser window  .maximize()

    import org.openqa.selenium.WebDriver; 
    import org.openqa.selenium.firefox.FirefoxDriver; 
    
    public class MaximizeWindow { 
    
     public static void main(String args[])
    { 
     
     WebDriver driver = new FirefoxDriver(); 
     
     driver.get("https://www.bing.com"); 
     
     driver.manage().window().maximize(); 
     
     //testingdocs comment : maximize browser window
     
    } 
    
    }

     

    Difference between .close() and .quit()

    driver.close() : this method closes the browser window that the driver has focus on.

    driver.quit(): this method calls dispose

    driver.dispose() : closes all browser windows opened by driver instance.and safely ends the session gracefully.

    Let see sample programs run in BrowserStack cloud demonstrating the difference between the 2 methods.

    Code Listing

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By; 
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver; 
    
    
    public class CloseAndQuit { 
     
     public static final String USERNAME="your_BROWSERSTACK_USERNAME";
     public static final String AUTOMATE_KEY = "YOUR_KEY";
     public static final String URL = "https://" + USERNAME + 
    ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
    
     
     public static void main(String[] args) throws MalformedURLException 
     { 
     DesiredCapabilities caps = new DesiredCapabilities();
     caps.setCapability("browser", "Firefox");
     caps.setCapability("browser_version", "45");
     caps.setCapability("os", "Windows");
     caps.setCapability("os_version", "10");
     caps.setCapability("browserstack.debug", "true");
     WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
     driver.get("http://www.testingdocs.com");
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(30, 
    TimeUnit.SECONDS);
     
     WebElement element =driver.
    findElement(By.partialLinkText("CONTACT"));
     Actions action=new Actions(driver);
     action.contextClick(element).perform();
     action.sendKeys("w").perform();
    
     
     // browser window close
     driver.close();
    
    } 
    
    }

     

    Quit will close all browser instances :
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    
    public class BrowserStackCloseAndQuit 
    {
     
     public static final String USERNAME = "your_username";
     public static final String AUTOMATE_KEY = "yourKey";
     public static final String URL = "https://" + USERNAME + 
    ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
    
     
    public static void main(String[] args) throws 
    MalformedURLException, InterruptedException 
    { 
     DesiredCapabilities caps = new DesiredCapabilities();
     caps.setCapability("browser", "Firefox");
     caps.setCapability("browser_version", "45");
     caps.setCapability("os", "Windows");
     caps.setCapability("os_version", "10");
     caps.setCapability("browserstack.debug", "true");
     WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
     driver.get("http://www.testingdocs.com");
     driver.manage().window().maximize();
     driver.manage().timeouts().
    implicitlyWait(30, TimeUnit.SECONDS);
     WebElement element =driver.
    findElement(By.partialLinkText("CONTACT"));
     Actions action=new Actions(driver);
     action.contextClick(element).perform();
     action.sendKeys("w").perform();
     
     
     // browser quit
     driver.quit();
    
    } 
    }

     

    Selenium Tutorial on this website:

    https://www.testingdocs.com/selenium-webdriver-tutorial/

    More information on Selenium, visit official website:

    https://www.selenium.dev/

    Related Posts

    Windows 10 Settings

    Selenium /

    Add Microsoft Webdriver on Windows OS

    Download Selenium Components

    Selenium /

    Getting Started with Selenium Webdriver

    LambdaTest Testing Cloud SaaS Platform

    Selenium /

    LambdaTest – Testing Cloud SaaS Platform

    Selenium /

    Selenium 3.0 and Mozilla GeckoDriver

    SauceLabs Website

    Selenium /

    Run an Example Test on SauceLabs

    ‹ Run BrowserStack Cloud Test› Sample Selenium Framework with TestNG

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com