# 第一種方法:focus (這個是元素正好在屏幕中間)
targetElem = browser.find_element_by_xpath("http://a[@id='pagnNextLink']")
browser.execute_script("arguments[0].focus();", targetElem)
# 第二種方法:scrollIntoView (這個是拖到底部了,有可能targetElem 不可見)
# targetElem = browser.find_element_by_xpath("http://a[@id='pagnNextLink']/span[@id='pagnNextString']")
# browser.execute_script("arguments[0].scrollIntoView();", targetElem)? ? # 拖動到可見的元素去
# 第三種方法:?targetElem 正好在底部顯示
targetElem.location_once_scrolled_into_view
# 第四種方法:?targetElem 正好在底部顯示
#向下滾動200px
browser.execute_script("window.scrollBy(0,200)","")
#向下滾動到頁面底部?
browser.execute_script("window.scrollBy(0,document.body.scrollHeight)","")
# 頁面內(nèi)DIV的滾動
targetElem = browser.find_element_by_xpath('//div[@class="photoGridWrapper"]')
browser.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', targetElem)
time.sleep(1)
selenium webdriver 如何實現(xiàn)將瀏覽器滾動條移動到某個位置
ActionChains(driver).move_to_element(****).perform()
將頁面定位到要查看的元素位置從而變相的實現(xiàn)了滾動條滾動的效果。問題解決
https://blog.csdn.net/xiaosongbk/article/details/70231564
from selenium.webdriver.common.action_chains import ActionChains
scroll_add_crowd_button = driver.find_element_by_xpath(xpath_button_add_crowd)
driver.execute_script("arguments[0].scrollIntoView();", scroll_add_crowd_button)
https://blog.csdn.net/HeatDeath/article/details/72322850