Unfortunately, Selenium do not provide any built-in function for minimizing the browser window, there is only function for maximizing the window. But there are some work around for doing this.
You want window to be out of sight, then you need to use this code. by using it browser window will be out of your sight and you will not be able to see what is running, but don't worry your test cases will keep on executing. It is tried and tested work around.
//Snippet
driver.manage().window().setPosition(new Point(-2000,0));
package com.neeraj.test.neeraj;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class ok {
public static WebDriver driver = new ChromeDriver();
@Test
public void add1() throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver.get("https://www.facebook.com");
driver.manage().window().setPosition(new Point(-2000,0));
}
}
You want window to be out of sight, then you need to use this code. by using it browser window will be out of your sight and you will not be able to see what is running, but don't worry your test cases will keep on executing. It is tried and tested work around.
//Snippet
driver.manage().window().setPosition(new Point(-2000,0));
package com.neeraj.test.neeraj;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class ok {
public static WebDriver driver = new ChromeDriver();
@Test
public void add1() throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
driver.get("https://www.facebook.com");
driver.manage().window().setPosition(new Point(-2000,0));
}
}
No comments:
Post a Comment