A simple example of the use of selenium python to automate the login 126 mailboxes

 

. 1  # encoding = UTF. 8- 
2  from Selenium Import the webdriver # imported packages
 . 3  Import Time
 . 4 
# Select browser driver . 5 Driver = webdriver.Chrome (executable_path = " C: \\ Program Files \\ \\ chromedriver Python36 " ) . 6 Driver .get ( " http://mail.126.com " ) # get request to send . 7 passwd_login_link = driver.find_element_by_id ( " switchAccountLogin " ) . 8 passwd_login_link.click () . 9 the time.sleep (. 1 ) 10 driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@id,'x-URS-iframe')]")) 11 12 user_name = driver.find_element_by_xpath("//input[@name='email']") 13 pass_wd = driver.find_element_by_xpath("//input[@name='password']") 14 login_button =driver.find_element_by_id("dologin") 15 16 user_name.clear() 17 user_name.send_keys("w465898125") 18 pass_wd.send_keys("Wen11281128#m") 19 login_button.click() 20 time.sleep(5) 21 22 assert "退出" in driver.page_source 23 24 logout_link = driver.find_element_by_xpath("//a[text()='退出']") 25 logout_link.click() 26 driver.close()

 

Guess you like

Origin www.cnblogs.com/wenm1128/p/11781014.html