10 examples of 'python selenium scroll to element' in Python

Every line of 'python selenium scroll to element' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
30def scroll_to(driver, el):
31 """
32 Scroll an element into view, using JS
33 """
34 try:
35 driver.execute_script("arguments[0].scrollIntoView();", el)
36 except SELENIUM_EXCEPTIONS:
37 return
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

484def scroll_to(self, x, y):
485 """
486 Scroll to a particular (x, y) coordinate.
487
488 :param x: the x coordinate to scroll to.
489 :type x: int
490 :param y: the y coordinate to scroll to.
491 :type y: int
492 :return:
493 """
494 # prevent script injection
495 x = int(x)
496 y = int(y)
497 self.execute_script('window.scrollTo({}, {});'.format(x, y))
1284def scroll_to(self, selector, by=By.CSS_SELECTOR,
1285 timeout=settings.SMALL_TIMEOUT):
1286 ''' Fast scroll to destination '''
1287 if self.demo_mode:
1288 self.slow_scroll_to(selector, by=by, timeout=timeout)
1289 return
1290 if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1291 timeout = self.__get_new_timeout(timeout)
1292 element = self.wait_for_element_visible(
1293 selector, by=by, timeout=timeout)
1294 try:
1295 self.__scroll_to_element(element)
1296 except (StaleElementReferenceException, ENI_Exception):
1297 self.wait_for_ready_state_complete()
1298 time.sleep(0.05)
1299 element = self.wait_for_element_visible(
1300 selector, by=by, timeout=timeout)
1301 self.__scroll_to_element(element)
42def scroll_down(self, wait=0.5):
43 self.driver.execute_script(
44 'window.scrollTo(0, document.body.scrollHeight)')
45 sleep(wait)
85def scroll(self, start_locator, end_locator):
86 """
87 Scrolls from one element to another
88 Key attributes for arbitrary elements are `id` and `name`. See
89 `introduction` for details about locating elements.
90 """
91 el1 = self._element_find(start_locator, True, True)
92 el2 = self._element_find(end_locator, True, True)
93 driver = self._current_application()
94 driver.scroll(el1, el2)
74def scroll_down(self, wait=0.3):
75 self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
76 randmized_sleep(wait)
373def scrollScreen(self,by1, value1, by2, value2):
374 self.driver.scroll(self.findMyElement(by1,value1), self.findMyElement(by2,value2))
653def scrollTo(self, x, y):
654 """
655 Scrolls to a particular set of coordinates in the document.
656 Syntax
657
658 window.scrollTo(x-coord, y-coord)
659
660 Parameters
661
662 x-coord is the pixel along the horizontal axis of the document that you
663 want displayed in the upper left.
664
665 y-coord is the pixel along the vertical axis of the document that you
666 want displayed in the upper left.
667 """
668 pass
50def test_scroll(self):
51 els = self.driver.find_elements_by_class_name('XCUIElementTypeButton')
52 els[5].click()
53
54 sleep(1)
55 try:
56 el = self.driver.find_element_by_accessibility_id('Allow')
57 el.click()
58 sleep(1)
59 except:
60 pass
61
62 el = self.driver.find_element_by_xpath('//XCUIElementTypeMap[1]')
63
64 location = el.location
65 self.driver.swipe(start_x=location['x'], start_y=location['y'], end_x=0.5, end_y=location['y'], duration=800)
18def window_scroll(self, width=None, height=None):
19 """
20 JavaScript API, Only support css positioning
21 Setting width and height of window scroll bar.
22 """
23 if width is None:
24 width = "0"
25 if height is None:
26 height = "0"
27 js = "window.scrollTo({w},{h});".format(w=str(width), h=(height))
28 self.driver.execute_script(js)

Related snippets