Skip to content

Commit ae46489

Browse files
committed
Add scroll_to_top() and scroll_to_bottom()
1 parent ca7b6c8 commit ae46489

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

help_docs/method_summary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ self.scroll_to(selector, by=By.CSS_SELECTOR)
172172

173173
self.slow_scroll_to(selector, by=By.CSS_SELECTOR)
174174

175+
self.scroll_to_top()
176+
177+
self.scroll_to_bottom()
178+
175179
self.click_xpath(xpath)
176180

177181
self.js_click(selector, by=By.CSS_SELECTOR, all_matches=False)

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,24 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR, timeout=None):
18261826
selector, by=by, timeout=timeout)
18271827
self.__slow_scroll_to_element(element)
18281828

1829+
def scroll_to_top(self):
1830+
scroll_script = "window.scrollTo(0, 0);"
1831+
try:
1832+
self.execute_script(scroll_script)
1833+
time.sleep(0.012)
1834+
return True
1835+
except Exception:
1836+
return False
1837+
1838+
def scroll_to_bottom(self):
1839+
scroll_script = "window.scrollTo(0, 10000);"
1840+
try:
1841+
self.execute_script(scroll_script)
1842+
time.sleep(0.012)
1843+
return True
1844+
except Exception:
1845+
return False
1846+
18291847
def click_xpath(self, xpath):
18301848
# Technically self.click() will automatically detect an xpath selector,
18311849
# so self.click_xpath() is just a longer name for the same action.

0 commit comments

Comments
 (0)