Skip to content

Commit 8480b8e

Browse files
[py] Allow 0 coordinates for the window position. Fixes #9574
Python is treating 0 as falsy types if we just use the `not` keyword. Being more explicit for that and added a few tests to make sure that we don't ever allow it.
1 parent 2530e56 commit 8480b8e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ def set_window_rect(self, x=None, y=None, width=None, height=None) -> dict:
13681368
driver.set_window_rect(x=10, y=10, width=100, height=200)
13691369
"""
13701370

1371-
if (not x and not y) and (not height and not width):
1371+
if (x is None and y is None) and (not height and not width):
13721372
raise InvalidArgumentException("x and y or height and width need values")
13731373

13741374
return self.execute(Command.SET_WINDOW_RECT, {"x": x, "y": y,

py/test/selenium/webdriver/common/window_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ def test_should_set_the_rect_of_the_current_window(driver):
114114
assert new_rect.get('height') == target_height
115115

116116

117+
def test_set_window_rect_should_accept_0_as_x_and_y(driver):
118+
from selenium.common.exceptions import InvalidArgumentException
119+
try:
120+
driver.set_window_rect(x=0, y=0)
121+
except InvalidArgumentException:
122+
pytest.fail("Should not have thrown InvalidArgumentException")
123+
124+
125+
def test_set_window_rect_throws_when_height_and_width_are_0(driver):
126+
from selenium.common.exceptions import InvalidArgumentException
127+
with pytest.raises(InvalidArgumentException):
128+
driver.set_window_rect(height=0, width=0)
129+
130+
117131
# @pytest.mark.xfail_safari(raises=WebDriverException,
118132
# reason='Fullscreen command not implemented')
119133
# @pytest.mark.skipif(os.environ.get('TRAVIS') == 'true',

0 commit comments

Comments
 (0)