Call JavaScript and
First, call JavaScript
1. Adjust browser scroll bar position
# left margin, top margin
2. Execute JavaScript code with Execute_script ()
js="Window.scrollto (0,500); " driver.execute_script (JS)
Example:
fromSeleniumImportWebdriver fromTimeImportSleepdriver=Webdriver. Chrome () Driver.get ("http://www.baidu.com")Driver.maximize_window () driver.find_element_by_id ("kw"). Send_keys ("Chen") driver.find_element_by_id ("su"). Click () Sleep (2)#to adjust the position of the browser scroll bar via JavaScriptjs="Window.scrollto (0,500);"driver.execute_script (JS) sleep (3) Driver.quit ()
Ps:
1. Scroll bar back to top:
Js= "var Q=document.getelementbyid (' id '). scrolltop=0"
Driver.execute_script (JS)
2. Scroll bar to the bottom
Js= "var q=document.documentelement.scrolltop=10000"
Driver.execute_script (JS)
Two
1.
Driver.get_screenshot_as_file ()
Example:
fromSeleniumImportWebdriver fromTimeImportSleepdriver=Webdriver. Chrome () Driver.get ("http://www.baidu.com")Driver.maximize_window () driver.find_element_by_id ("kw"). Send_keys ("Chen") driver.find_element_by_id ("su"). Click () Sleep (2)#intercepts the current window and savesDriver.get_screenshot_as_file ("e:\\chen.jpg") Driver.quit ()
Python+selenium Personal Learning Note 10-call JavaScript and