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