Perform the following steps:
- window.scrollTo (x, y) method, the browser window is provided in the horizontal and vertical scroll bars position (first argument represents the horizontal pitch of the left, the second parameter represents a vertical margin)
- execute_script () method is executed js code
. 1 from Selenium Import the webdriver 2 Import Time . 3 . 4 Driver = webdriver.Chrome () . 5 driver.set_window_size (700, 700) # Set the size of the browser window, for the horizontal and vertical scroll bars appear . 6 driver.get ( ' HTTP: // www.baidu.com ' ) . 7 . 8 driver.find_element_by_id ( ' kW ' ) .send_keys ( ' FDAs ' ) . 9 driver.find_element_by_id ( ' SU ' ) .click () 10 . 11 the time.sleep (2 ) 12 is 13 is Print ( ' ------------------ ' ) 14 JS = " the window.scrollTo (100,450); " # scrollbar of the browser window position setting 15 driver.execute_script (JS) # to move the position of the slider by executing JavaScript code 16 . 17 the time.sleep (10 ) 18 is driver.quit ()
Results as shown: