Is there a way to scroll down on a page until a certain element pops up ? #2367
Answered
by
mdmintz
elnatan2604
asked this question in
Q&A
|
As I ask on the title, is there a way to do it? |
Answered by
mdmintz
Dec 16, 2023
Replies: 1 comment 4 replies
|
There are several scroll methods that you can work with: self.scroll_to(selector, by="css selector", timeout=None)
# Duplicates: self.scroll_to_element(selector, by="css selector")
self.slow_scroll_to(selector, by="css selector", timeout=None)
# Duplicates: self.slow_scroll_to_element(selector, by="css selector")
self.scroll_into_view(selector, by="css selector", timeout=None)
self.scroll_to_top()
self.scroll_to_bottom()If the element that you want to interact with is already in the html, (but not visible yet), then you can use from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class MyTestClass(BaseCase):
def test_base(self):
self.open("URL")
for i in range(20):
self.execute_script("window.scrollTo(0, %s);" % (i * 100))
if self.is_element_visible("SELECTOR"):
break
self.sleep(0.1) |
4 replies
Answer selected by
mdmintz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are several scroll methods that you can work with:
If the element that you want to interact with is already in the html, (but not visible yet), then you can use
self.js_click(selector)to click on the hidden element. If that's not enough, you can create a loop where you call one of the scroll methods and then check fo…