Exercise 1: Log in to multiple email accounts using a data-driven approach Login_info.txt:[email protected]163. Com,xxxx[email protected]163. com,xxxxmain.py: fromSeleniumImportWebdriverImportTimewith Open ("Login_info.txt") as FP: forDatainchFp:username_data,password_data= Data.strip (). Split (",") Driver=webdriver. Ie (executable_path="C:\\iedriverserver") Driver.get ("http://mail.163.com") Time.sleep (5) Frame=driver.find_element_by_xpath ("//iframe[@id = ' x-urs-iframe ')") Driver.switch_to_frame (frame) Username=driver.find_element_by_xpath ("//input[@placeholder = ' email account or phone number ' and @name = ' email '") Password=driver.find_element_by_xpath ("//input[@placeholder = ' password ')") Submit_button=driver.find_element_by_xpath ("//a[@id = ' dologin ')") Username.clear () password.clear () Username.send_keys (Username_data) Password.send_keys (p Assword_data) Submit_button.click () Time.sleep (15) driver.switch_to_default_content ()assertU"Exit" inchdriver.page_source driver.quit ()
"Webdriver Automation" uses a data-driven approach to login to multiple 163 accounts