@@ -797,6 +797,7 @@ def get_screenshot_as_file(self, filename) -> bool:
797797 warnings .warn (
798798 "name used for saved screenshot does not match file type. It should end with a `.png` extension" ,
799799 UserWarning ,
800+ stacklevel = 2 ,
800801 )
801802 png = self .get_screenshot_as_png ()
802803 try :
@@ -857,8 +858,7 @@ def set_window_size(self, width, height, windowHandle: str = "current") -> None:
857858
858859 driver.set_window_size(800,600)
859860 """
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 )
862862 self .set_window_rect (width = int (width ), height = int (height ))
863863
864864 def get_window_size (self , windowHandle : str = "current" ) -> dict :
@@ -870,8 +870,6 @@ def get_window_size(self, windowHandle: str = "current") -> dict:
870870 driver.get_window_size()
871871 """
872872
873- if windowHandle != "current" :
874- warnings .warn ("Only 'current' window is supported for W3C compatible browsers." )
875873 size = self .get_window_rect ()
876874
877875 if size .get ("value" , None ):
@@ -891,8 +889,7 @@ def set_window_position(self, x, y, windowHandle: str = "current") -> dict:
891889
892890 driver.set_window_position(0,0)
893891 """
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 )
896893 return self .set_window_rect (x = int (x ), y = int (y ))
897894
898895 def get_window_position (self , windowHandle = "current" ) -> dict :
@@ -904,12 +901,16 @@ def get_window_position(self, windowHandle="current") -> dict:
904901 driver.get_window_position()
905902 """
906903
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 )
909905 position = self .get_window_rect ()
910906
911907 return {k : position [k ] for k in ("x" , "y" )}
912908
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+
913914 def get_window_rect (self ) -> dict :
914915 """Gets the x, y coordinates of the window as well as height and width
915916 of the current window.
0 commit comments