Skip to content

Commit 95ccb82

Browse files
jugglinmikeAutomatedTester
authored andcommitted
[py] Raise error for unsupported method
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
1 parent 902d27d commit 95ccb82

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
from .file_detector import FileDetector, LocalFileDetector
3232
from selenium.common.exceptions import (InvalidArgumentException,
3333
WebDriverException,
34-
NoSuchCookieException)
34+
NoSuchCookieException,
35+
UnknownMethodException)
3536
from selenium.webdriver.common.by import By
3637
from selenium.webdriver.common.html5.application_cache import ApplicationCache
3738

@@ -1222,7 +1223,9 @@ def get_window_rect(self):
12221223
def set_window_rect(self, x=None, y=None, width=None, height=None):
12231224
"""
12241225
Sets the x, y coordinates of the window as well as height and width of
1225-
the current window.
1226+
the current window. This method is only supported for W3C compatible
1227+
browsers; other browsers should use `set_window_position` and
1228+
`set_window_size`.
12261229
12271230
:Usage:
12281231
::
@@ -1231,6 +1234,9 @@ def set_window_rect(self, x=None, y=None, width=None, height=None):
12311234
driver.set_window_rect(width=100, height=200)
12321235
driver.set_window_rect(x=10, y=10, width=100, height=200)
12331236
"""
1237+
if not self.w3c:
1238+
raise UnknownMethodException("set_window_rect is only supported for W3C compatible browsers")
1239+
12341240
if (x is None and y is None) and (height is None and width is None):
12351241
raise InvalidArgumentException("x and y or height and width need values")
12361242

0 commit comments

Comments
 (0)