[英]Python Selenium Page scrolling and clicking next button
是否有人可以使用python代码从页面顶部到页面底部滚动,然后单击按钮在浏览器中加载更多页面?
To scroll to the bottom of the page you can use: 要滚动到页面底部,可以使用:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
To click on a button you can use: 要单击按钮,可以使用:
driver.find_element_by_css_selector('.button.c_button.s_button').click()
可能您可以使用JS
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
You can use below code to scroll page down to the bottom: 您可以使用以下代码将页面向下滚动到底部:
from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.END)
Or if you want to scroll down to exact button to be able to click it: 或者,如果您想向下滚动到确切按钮以单击它:
button = driver.find_element_by_xpath('//button[text()="Next"]') # Selector might differs
button.location_once_scrolled_into_view
button.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.