In the login 126 mailbox when there are several pits, to perfect avoid can look at the following, directly on the code:
#encoding = Utf-8
From selenium import Webdriver
Import UnitTest
Import time
Class login126 (UnitTest. TestCase):
def setUp (self):
Self.driver = Webdriver. Chrome (Executable_path = "Chromedriver")
def test_login (self):
Self.driver.get ("https://mail.126.com/")
Time.sleep (3)
#此处的登录框是在iframe里, so be sure to enter the IFRAME before you can find the element
Self.driver.switch_to.frame (Self.driver.find_element_by_xpath (".//*[@id = ' x-urs-iframe ')")
Time.sleep (3)
#登录和密码输入框要切记不要用ID来进行定位, each login ID will change.
Self.driver.find_element_by_xpath (".//*[@data-placeholder= ' email account or phone number ']"). Send_keys (' xxxx ')
Self.driver.find_element_by_xpath ('//*[@data-placeholder= "password"]). Send_keys (' xxxxx ')
Self.driver.find_element_by_xpath ('//*[@id = "Dologin"]). Click ()
# # Self.driver.switch_to.default_content ()
#断言前要等待页面加载出来后在进行断言
Time.sleep (10)
Assert u ' exit ' in Self.driver.page_source
def tearDown (self):
Self.driver.quit ()
if __name__ = = ' __main__ ':
Unittest.main ()
Python2+selenium+mail, automatic login 126 mailbox