Skip to content

Commit

Permalink
[py] Raise error for unsupported method
Browse files Browse the repository at this point in the history
The Selenium wire protocol does not define a "set window rect" method
[1]. Although similar behavior can be achieved by composing available
methods, doing so could lead to observable differences with WebDriver
(for instance, depending on the order the methods are invoked) and cause
issues when migrating.

Immediately raise an exception if the `set_window_rect` method is
invoked for a browser which uses the Selenium wire protocol. Extend the
method's documentation to include a recommendation on how to update
call sites in a forward-compatible way.

[1] https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
  • Loading branch information
jugglinmike authored and AutomatedTester committed Apr 17, 2019
1 parent 902d27d commit 95ccb82
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from .file_detector import FileDetector, LocalFileDetector
from selenium.common.exceptions import (InvalidArgumentException,
WebDriverException,
NoSuchCookieException)
NoSuchCookieException,
UnknownMethodException)
from selenium.webdriver.common.by import By
from selenium.webdriver.common.html5.application_cache import ApplicationCache

Expand Down Expand Up @@ -1222,7 +1223,9 @@ def get_window_rect(self):
def set_window_rect(self, x=None, y=None, width=None, height=None):
"""
Sets the x, y coordinates of the window as well as height and width of
the current window.
the current window. This method is only supported for W3C compatible
browsers; other browsers should use `set_window_position` and
`set_window_size`.
:Usage:
::
Expand All @@ -1231,6 +1234,9 @@ def set_window_rect(self, x=None, y=None, width=None, height=None):
driver.set_window_rect(width=100, height=200)
driver.set_window_rect(x=10, y=10, width=100, height=200)
"""
if not self.w3c:
raise UnknownMethodException("set_window_rect is only supported for W3C compatible browsers")

if (x is None and y is None) and (height is None and width is None):
raise InvalidArgumentException("x and y or height and width need values")

Expand Down

0 comments on commit 95ccb82

Please sign in to comment.