1. Multi-Window switching
Browser.window_handles Show All Handles
Browser.current_window_handle Show Current handle
Browser.switch_to_window (browser.window_handles[1]) toggle Handle
2. JS dialog box processing
alter = Browser.find_element_by_xpath ('//*[@id = "Topguideloginform"]/div[4]/button '). Click ()
Switch_to_alert () cut to alter returns an Alter object
Alter.accept () Confirm
Alter.dismiss () Cancel
Send_keys () have input box to use, otherwise error
#coding =utf-8
from Selenium import webdriver
Import Time
Browser = Webdriver. Chrome ()
Browser.get (' http://bbs.tianya.cn/#loginAction ')
Time.sleep (2)
browser.find_element_by_id ("vwriter"). Send_keys ("Zhang")
Time.sleep (1)
browser.find_element_by_id ("Vpassword"). Send_keys ("1234526526672")
Time.sleep (2)
Browser.find_element_by_xpath ('//*[@id = "Topguideloginform"]/div[4]/button '). Click ()
Time.sleep (1)
alter = Browser.switch_to_alert ()
Time.sleep (1)
Alter.dismiss ()
Web Automation 6-selenium Multi-window switch and JS dialog box processing