@@ -282,6 +282,18 @@ def safe_execute_script(driver, script):
282282 This method will load jQuery if it wasn't already loaded."""
283283 try :
284284 execute_script (driver , script )
285+ except TypeError as e :
286+ if (
287+ (
288+ shared_utils .is_cdp_swap_needed (driver )
289+ or hasattr (driver , "_swap_driver" )
290+ )
291+ and "cannot unpack non-iterable" in str (e )
292+ ):
293+ pass
294+ else :
295+ activate_jquery (driver ) # It's a good thing we can define it here
296+ execute_script (driver , script )
285297 except Exception :
286298 # The likely reason this fails is because: "jQuery is not defined"
287299 activate_jquery (driver ) # It's a good thing we can define it here
@@ -1311,22 +1323,34 @@ def slow_scroll_to_element(driver, element, *args, **kwargs):
13111323 element_location_y = None
13121324 try :
13131325 if shared_utils .is_cdp_swap_needed (driver ):
1314- element .get_position ().y
1326+ element_location_y = element .get_position ().y
13151327 else :
13161328 element_location_y = element .location ["y" ]
13171329 except Exception :
1318- element .location_once_scrolled_into_view
1330+ if shared_utils .is_cdp_swap_needed (driver ):
1331+ element .scroll_into_view ()
1332+ else :
1333+ element .location_once_scrolled_into_view
13191334 return
13201335 try :
1321- element_location_x = element .location ["x" ]
1336+ if shared_utils .is_cdp_swap_needed (driver ):
1337+ element_location_x = element .get_position ().x
1338+ else :
1339+ element_location_x = element .location ["x" ]
13221340 except Exception :
13231341 element_location_x = 0
13241342 try :
1325- element_width = element .size ["width" ]
1343+ if shared_utils .is_cdp_swap_needed (driver ):
1344+ element_width = element .get_position ().width
1345+ else :
1346+ element_width = element .size ["width" ]
13261347 except Exception :
13271348 element_width = 0
13281349 try :
1329- screen_width = driver .get_window_size ()["width" ]
1350+ if shared_utils .is_cdp_swap_needed (driver ):
1351+ screen_width = driver .cdp .get_window_size ()["width" ]
1352+ else :
1353+ screen_width = driver .get_window_size ()["width" ]
13301354 except Exception :
13311355 screen_width = execute_script (driver , "return window.innerWidth;" )
13321356 element_location_y = element_location_y - constants .Scroll .Y_OFFSET
0 commit comments