|
28 | 28 | from .switch_to import SwitchTo
|
29 | 29 | from .mobile import Mobile
|
30 | 30 | from .file_detector import FileDetector, LocalFileDetector
|
31 |
| -from selenium.common.exceptions import WebDriverException |
| 31 | +from selenium.common.exceptions import (InvalidArgumentException, |
| 32 | + WebDriverException) |
32 | 33 | from selenium.webdriver.common.by import By
|
33 | 34 | from selenium.webdriver.common.html5.application_cache import ApplicationCache
|
34 | 35 |
|
@@ -903,6 +904,32 @@ def get_window_position(self, windowHandle='current'):
|
903 | 904 | return self.execute(Command.GET_WINDOW_POSITION, {
|
904 | 905 | 'windowHandle': windowHandle})['value']
|
905 | 906 |
|
| 907 | + def get_window_rect(self): |
| 908 | + """ |
| 909 | + Gets the x, y coordinates of the window as well as height and width of |
| 910 | + the current window. |
| 911 | +
|
| 912 | + :Usage: |
| 913 | + driver.get_window_rect() |
| 914 | + """ |
| 915 | + return self.execute(Command.GET_WINDOW_RECT)['value'] |
| 916 | + |
| 917 | + def set_window_rect(self, x=None, y=None, width=None, height=None): |
| 918 | + """ |
| 919 | + Sets the x, y coordinates of the window as well as height and width of |
| 920 | + the current window. |
| 921 | +
|
| 922 | + :Usage: |
| 923 | + driver.set_window_rect(x=10, y=10) |
| 924 | + driver.set_window_rect(width=100, height=200) |
| 925 | + driver.set_window_rect(x=10, y=10, width=100, height=200) |
| 926 | + """ |
| 927 | + if (x is None and y is None) and (height is None and width is None): |
| 928 | + raise InvalidArgumentException("x and y or height and width need values") |
| 929 | + |
| 930 | + return self.execute(Command.SET_WINDOW_RECT, {"x": x, "y": y, |
| 931 | + "width": width, |
| 932 | + "height": height})['value'] |
906 | 933 | @property
|
907 | 934 | def file_detector(self):
|
908 | 935 | return self._file_detector
|
|
0 commit comments