1

Example code:

from selenium import webdriver

browser = webdriver.Chrome() 
browser.minimize_window()

Returns the following exception:

  File "myScript.py", line 4, in <module>
    browser.minimize_window()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 738, in minimize_window
    self.execute(Command.MINIMIZE_WINDOW)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: unknown command: session/8252be05ea571a2c623450db8ba097c0/window/minimize

Adding the line

print dir(browser)

Shows that minimize_window() is a listed function of browser. So what gives? Is this functionality just not compatible with Chrome?

Python 2.7

Andersson
  • 51,635
  • 17
  • 77
  • 129
Satki
  • 99
  • 2
  • 11

2 Answers2

1

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown command: session/8252be05ea571a2c623450db8ba097c0/window/minimize

...implies that the call to minimize_window() function wasn't recoznized.

You spotted it correct. As now WebDriver Specification is a W3C Recommendation the function defination for maximizing the window was adjusted as per the W3C Recommended Specification as follows:

def maximize_window(self):
    """
    Maximizes the current window that webdriver is using
    """
    params = None
    command = Command.W3C_MAXIMIZE_WINDOW
    if not self.w3c:
        command = Command.MAXIMIZE_WINDOW
        params = {'windowHandle': 'current'}
    self.execute(command, params)
    

But, the function defination for minimizing the window is still pending to be W3C compliant within the Python Client as is still defined as:

def minimize_window(self):
    """
    Invokes the window manager-specific 'minimize' operation
    """
    self.execute(Command.MINIMIZE_WINDOW)
    

Hence you see the error:

unknown command: session/8252be05ea571a2c623450db8ba097c0/window/minimize

Solution

As the default/common practice is to open the browser in maximized mode, while Test Execution is In Progress minimizing the browser would be against the best practices as Selenium may loose the focus over the Browsing Context and an exception may raise during the Test Execution. However, Selenium's client does have a minimize_window() method which eventually pushes the Chrome Browsing Context effectively to the background.

Python:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
driver.minimize_window()

Java Solution:

driver.navigate().to("https://www.google.com/");
Point p = driver.manage().window().getPosition();
Dimension d = driver.manage().window().getSize();
driver.manage().window().setPosition(new Point((d.getHeight()-p.getX()), (d.getWidth()-p.getY())));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • And how would you explain that `minimize_window` works in Python 3.6 with exactly the same method definition? – Andersson Nov 16 '18 at 10:45
-1

Just tried to downgrade my chromedriver version to 2.25 and got...

selenium.common.exceptions.WebDriverException: Message: unknown command: session/f35727d2129895c35b24deeb7090eb26/window/minimize

with the same code.

But if to use the last (2.43) it work just fine

So just upgrade to up-to-date chromedriver version to be able to use minimize_window method

Community
  • 1
  • 1
Andersson
  • 51,635
  • 17
  • 77
  • 129