0

When I run this code

url = 'https://www.google.com'
driver = webdriver.Firefox()
driver.get(url)
print(driver.get_window_position())'

I get this error

selenium.common.exceptions.WebDriverException: Message: GET /session/bbb48fc8-51ba-4cff-b639-771f80489785/window/rect did not match a known command

The error seems to be in the get_window_position() method. Any idea?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Javier
  • 1
  • 1
  • 2
    Usually things like ` did not match a known command` is because of a mismatch between Selenium/webdriver/browser versions. Be sure to update to latest version of selnium, geckodriver, and Firefox. Please update with the versions you're using. – sytech Dec 10 '18 at 18:54
  • It worked for me on my local machine. I think yours selenium needs to be updated. – Himanshu Poddar Dec 11 '18 at 06:08

1 Answers1

0

This error message...

selenium.common.exceptions.WebDriverException: Message: GET /session/bbb48fc8-51ba-4cff-b639-771f80489785/window/rect did not match a known command

...implies that the GET method on the /session/{session id}/window/rect endpoint i.e. Get Window Rect failed.


get_window_position

get_window_position() gets the x,y position of the current window.

  • Usage:

    driver.get_window_position()
    

Note: Supported for W3C compatibile browsers.

I have used your own code at on my Windows 8 box as follows:

from selenium import webdriver

url = 'https://www.google.com'
driver = webdriver.Firefox()
driver.get(url)
print(driver.get_window_position())

But unable to reproduce the error/issue.


However at this point it is worth to mention that different Browser Clients renders the HTML in a different way. You can find a relevant discussion in Chrome & Firefox on Windows vs Linux (selenium).

It is possible as per your Test Configuration the Client (i.e. the Web Browser) returned back the control to the WebDriver instance i.e. 'document.readyState' equal to "complete" before the /session/{session id}/window/rect endpoint was established.

Solution

Induce WebDriverWait before you try to extract the window_position as follows:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    url = 'https://www.google.com'
    driver = webdriver.Firefox()
    driver.get(url)
    WebDriverWait(driver, 10).until(EC.title_contains("Google"))
    print(driver.get_window_position())
    
  • Console Output:

    {'x': -8, 'y': -8}
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352