简体   繁体   中英

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM