Mankdavix
Mankdavix

Reputation: 230

How to minimize a window using selenium webdriver

I need to minimize my web driver(chrome driver)in java and I have used:

driver.manage().window().setPosition(new Point(0, -1000));

but there's an error saying:

can not find the symbol Point

What is needed to be done? Dose the Point need to be declared or headers need to be included?

Upvotes: 1

Views: 3843

Answers (5)

Ali Azam
Ali Azam

Reputation: 2115

Use selenium Dimension(int w, int h) method with (0, 0) dimension.

driver.manage().window().setPosition(new org.openqa.selenium.Point(0, 0));
driver.manage().window().setSize(new org.openqa.selenium.Dimension(0, 0));

Upvotes: 0

Mankdavix
Mankdavix

Reputation: 230

The answer would be

import java.lang.Object;  
import org.openqa.selenium.Point;

these must be imported to make

driver.manage().window().setPosition(new Point(0, -1000));

this will place the window out of visible range

for Dimensions

    import java.lang.Object;  
    import org.openqa.selenium.Dimension;

and the code be

Dimension d=new Dimension(200, 300);
driver.manage().window().setSize(d);

this will only resize the window by Dimension( x, y)

we can also use robot class

import java.awt.Robot;  
import java.awt.event.KeyEvent;

and the code for this is (ALT+Space+N)

        `   Robot robot=new Robot();
            robot.keyPress(KeyEvent.VK_ALT);
            robot.keyPress(KeyEvent.VK_SPACE);
            Thread.sleep(100);
            robot.keyPress(KeyEvent.VK_N);
            Thread.sleep(300);
            robot.keyRelease(KeyEvent.VK_ALT);
            robot.keyRelease(KeyEvent.VK_SPACE);
            robot.keyRelease(KeyEvent.VK_N);`

this will minimise the window

Upvotes: 1

morty
morty

Reputation: 154

You can use selenium without opening the browser in the first place :)

//import the selenium web driver
var webdriver = require('selenium-webdriver');

var chromeCapabilities = webdriver.Capabilities.chrome();
//setting chrome options to be headless so that chrome browser doesn't pop up
var chromeOptions = {
    'args': ["--headless"]
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().withCapabilities(chromeCapabilities).build();

Upvotes: 0

Mahesh Telange
Mahesh Telange

Reputation: 14

Use this:

Dimension d=new Dimension(200, 300);
driver.manage().window().setSize(d);

Upvotes: 0

Grasshopper
Grasshopper

Reputation: 9058

Use the setSize(Dimension dim) method of Webdriver.Window.

driver.window.setSize(new Dimension(0,0))

Upvotes: 0

Related Questions