MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / __old_scroll_to_element

Function __old_scroll_to_element

seleniumbase/fixtures/js_utils.py:1299–1341  ·  view source on GitHub ↗
(driver, element)

Source from the content-addressed store, hash-verified

1297
1298
1299def __old_scroll_to_element(driver, element):
1300 # Firefox still needs this
1301 # because it doesn't have scrollIntoViewIfNeeded()
1302 element_location_y = None
1303 element_location_x = None
1304 element_width = 0
1305 screen_width = 0
1306 try:
1307 element_location_y = element.location["y"]
1308 except Exception:
1309 return False
1310 try:
1311 element_location_x = element.location["x"]
1312 except Exception:
1313 element_location_x = 0
1314 try:
1315 element_width = element.size["width"]
1316 except Exception:
1317 element_width = 0
1318 try:
1319 screen_width = driver.get_window_size()["width"]
1320 except Exception:
1321 screen_width = execute_script(driver, "return window.innerWidth;")
1322 element_location_y = element_location_y - constants.Scroll.Y_OFFSET
1323 if element_location_y < 0:
1324 element_location_y = 0
1325 element_location_x_fix = element_location_x - 400
1326 if element_location_x_fix < 0:
1327 element_location_x_fix = 0
1328 if element_location_x + element_width <= screen_width:
1329 element_location_x_fix = 0
1330 scroll_script = "window.scrollTo(%s, %s);" % (
1331 element_location_x_fix, element_location_y
1332 )
1333 # The old jQuery scroll_script required by=By.CSS_SELECTOR
1334 # scroll_script = "jQuery('%s')[0].scrollIntoView()" % selector
1335 # This other scroll_script does not centralize the element
1336 # execute_script(driver, "arguments[0].scrollIntoView();", element)
1337 try:
1338 execute_script(driver, scroll_script)
1339 return True
1340 except Exception:
1341 return False
1342
1343
1344def slow_scroll_to_element(driver, element, *args, **kwargs):

Callers 1

scroll_to_elementFunction · 0.85

Calls 2

execute_scriptFunction · 0.85
get_window_sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…