@@ -797,6 +797,7 @@ def get_screenshot_as_file(self, filename) -> bool:
797
797
warnings .warn (
798
798
"name used for saved screenshot does not match file type. It should end with a `.png` extension" ,
799
799
UserWarning ,
800
+ stacklevel = 2 ,
800
801
)
801
802
png = self .get_screenshot_as_png ()
802
803
try :
@@ -857,8 +858,7 @@ def set_window_size(self, width, height, windowHandle: str = "current") -> None:
857
858
858
859
driver.set_window_size(800,600)
859
860
"""
860
- if windowHandle != "current" :
861
- warnings .warn ("Only 'current' window is supported for W3C compatible browsers." )
861
+ self ._check_if_window_handle_is_current (windowHandle )
862
862
self .set_window_rect (width = int (width ), height = int (height ))
863
863
864
864
def get_window_size (self , windowHandle : str = "current" ) -> dict :
@@ -870,8 +870,6 @@ def get_window_size(self, windowHandle: str = "current") -> dict:
870
870
driver.get_window_size()
871
871
"""
872
872
873
- if windowHandle != "current" :
874
- warnings .warn ("Only 'current' window is supported for W3C compatible browsers." )
875
873
size = self .get_window_rect ()
876
874
877
875
if size .get ("value" , None ):
@@ -891,8 +889,7 @@ def set_window_position(self, x, y, windowHandle: str = "current") -> dict:
891
889
892
890
driver.set_window_position(0,0)
893
891
"""
894
- if windowHandle != "current" :
895
- warnings .warn ("Only 'current' window is supported for W3C compatible browsers." )
892
+ self ._check_if_window_handle_is_current (windowHandle )
896
893
return self .set_window_rect (x = int (x ), y = int (y ))
897
894
898
895
def get_window_position (self , windowHandle = "current" ) -> dict :
@@ -904,12 +901,16 @@ def get_window_position(self, windowHandle="current") -> dict:
904
901
driver.get_window_position()
905
902
"""
906
903
907
- if windowHandle != "current" :
908
- warnings .warn ("Only 'current' window is supported for W3C compatible browsers." )
904
+ self ._check_if_window_handle_is_current (windowHandle )
909
905
position = self .get_window_rect ()
910
906
911
907
return {k : position [k ] for k in ("x" , "y" )}
912
908
909
+ def _check_if_window_handle_is_current (windowHandle : str ) -> None :
910
+ """Warns if the window handle is not equal to `current`."""
911
+ if windowHandle != "current" :
912
+ warnings .warn ("Only 'current' window is supported for W3C compatible browsers." , stacklevel = 2 )
913
+
913
914
def get_window_rect (self ) -> dict :
914
915
"""Gets the x, y coordinates of the window as well as height and width
915
916
of the current window.
0 commit comments