5, Selenium+python automatic login 163 mailbox Send mail

Source: Internet
Author: User
Tags xpath

1, selenium to achieve automation, need to locate elements, the following view 163 mailbox login Elements

(1) Login (navigate to the Login box, the login box is an IFRAME, if not located to the IFRAME, is unable to locate the Account box and password box)

Navigate to the Mailbox box (name= ' email ')

Navigate to the Password box (name= ' password ')

Navigate to the Login button (id= "dologin")

2. Code implementation

#coding =utf-8import timefrom Selenium Import webdriverbroswer = Webdriver. Ie () broswer.get ("https://mail.163.com/") # Enter the specified URL broswer.switch_to.frame (' x-urs-iframe ') # login box is an IFRAME, cannot be located to that point, You cannot find the account and password text box broswer.find_element_by_name (' email '). Clear () # Clears the Account box information broswer.find_element_by_name (' email '). Send_ Keys (' Nancywangdl ') # Navigate to the Account box Broswer.find_element_by_name (' Password '). Send_keys (' password ') # Navigate to Password box login = Broswer.find_ Element_by_css_selector ("#dologin") # Navigate to the Login button Login.click () # Click the "Login" button Time.sleep (6) # wait 6 seconds broswer.find_element_by_id ("_mail_component_70_70"). Click () # Tap the "write" button Time.sleep (2) broswer.find_element_by_class_name (' Nui-editableaddr-ipt '). Send_keys (' [email protected] ') # Enter the recipient mailbox Broswer.find_element_by_xpath ("//input[@ Class= ' nui-ipt-input ' and @type = ' text ' and @maxlength = ' "]"). Send_keys (U ' Test ') XPath = Broswer.find_element_by_xpath ("//div[@class = ' app-editor-edtr ']/iframe") broswer.switch_to_frame (XPath) broswer.find_element_by_xpath ("//body[ @class = ' Nui-scroll ' and @conteNteditable= ' true '). Send_keys (U ' This is an automated test message ') broswer.switch_to_default_content () Broswer.find_element_by_xpath ("//div[@class = ' Nui-toolbar-item ']/div/span[2]"). Click () time.sleep (3) Broswer.quit () # Exit Browser

  

5, Selenium+python automatic login 163 mailbox Send mail

Related Article

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.