Use the Up,down button in the lower right corner of the keyboard to handle the page scroll bar This method is very flexible to use very convenient!!!!
fromSeleniumImportWebdriverImport Time fromSelenium.webdriver.common.keysImportKeys#visit BaiduDriver=Webdriver. Chrome () Driver.get ("http://www.baidu.com")#SearchDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys ("Selenium") driver.find_element_by_id ("su"). Click () time.sleep (3)#Drag the page scroll bar to the bottom by pressing the DOWN ARROW keyDriver.find_element_by_xpath ("//*[@id = ' page ']/a[10]"). Send_keys (Keys.down)Print 'pull the scroll bar to the end'Time.sleep (2) Driver.find_element_by_xpath ("//*[@id = ' s_tab ']/a[9]"). Send_keys (keys.up)Print 'pull the scroll bar to the upper end'Time.sleep (2) Driver.find_element_by_xpath ("//*[@id = ' Con-ar ']/div[3]/a"). Send_keys (Keys.down)Print 'pull the scroll bar to the middle'
You can also tune the JS script to handle the scroll bar, but this method I tried many times did not succeed, nor error, that is, did not respond, do not know why!
#Coding=utf-8 fromSeleniumImportWebdriverImport Time#visit BaiduDriver=Webdriver. Firefox () Driver.get ("http://www.baidu.com") #SearchDRIVER.FIND_ELEMENT_BY_ID ("kw"). Send_keys ("Selenium") driver.find_element_by_id ("su"). Click () time.sleep (3) #Drag the page scroll bar to the bottomjs="var q=document.documentelement.scrolltop=100000"driver.execute_script (JS) time.sleep (3) #move the scroll bar to the top of the pagejs="var q=document.documentelement.scrolltop=0"driver.execute_script (JS) time.sleep (3) #move the page scroll bar anywhere on the page to change the value after the equals signjs="var q=document.documentelement.scrolltop=50"Driver.execute_script (JS)
" "' to manipulate the scroll bars in the prompt Warning window in the page, first navigate to the inline window, and js= "var Q=document.getelementbyid (' id ') in the scroll bar operation. scrolltop=100000" Driver.execute_script (JS) time.sleep (3)" "
Python Selenium webdriver handles browser scroll bar