Python2+selenium+mail, automatic login 126 mailbox

Source: Internet
Author: User
Tags email account

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.