python webdriver 登陸163郵箱給QQ郵箱發送一個郵件,顯示等待

來源:互聯網
上載者:User

標籤:put   login   cas   ack   name   .com   輸入框   print   time   

#encoding=utf-8

import unittest

import time

from selenium import webdriver

from selenium.webdriver import ActionChains

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.common.exceptions import TimeoutException, NoSuchElementException

import traceback

 

class Visit163ByFirefox(unittest.TestCase):

 

    def setUp(self):

        #啟動IE瀏覽器

        self.driver=webdriver.Firefox(executable_path=‘d:\\geckodriver‘)

        #self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer")

       

    def test_HandleIFrame(self):

       

        url = "https://mail.163.com/"

        # 訪問自動以測試網頁

        self.driver.get(url)

        try:

            #顯示等待

            wait=WebDriverWait(self.driver,15,0.2)

            #切換frame

            self.driver.switch_to.frame(self.driver.find_element_by_xpath("//*[@id=‘x-URS-iframe‘]"))

            #self.driver.switch_to.frame("x-URS-iframe")

            #顯示等待擷取使用者名稱輸入框元素

            name=wait.until(lambda x:x.find_element_by_xpath("//*[@class=‘j-inputtext dlemail‘]"))

            name.send_keys("xxxxx")

            #顯示等待擷取密碼輸入框元素

            passwd=wait.until(lambda x:x.find_element_by_xpath("//*[@class=‘j-inputtext dlpwd‘]"))

            passwd.send_keys("xxxxx")

            #登入

            login=wait.until(lambda x:x.find_element_by_id("dologin"))

            login.click()

            #切回到預設framae

            self.driver.switch_to.default_content()

            #擷取寫信按鈕元素

            iwrite=wait.until(lambda x:x.find_element_by_xpath("//li[@id=‘_mail_component_74_74‘]/*[@class=‘oz0‘]"))

            iwrite.click()

            #擷取收件者輸入框元素

            receiver=wait.until(lambda x:x.find_element_by_xpath("//input[@class=‘nui-editableAddr-ipt‘ and @role=‘combobox‘]"))

            #receiver.click()

            receiver.send_keys("[email protected]")

            #擷取主題輸入框元素

            theme=wait.until(lambda x:x.find_element_by_xpath("//input[@class=‘nui-ipt-input‘ and @type=‘text‘ and @maxlength=‘256‘]"))

            #theme.click()

            theme.send_keys(u"這是夏曉旭的第一個自動化發郵件指令碼!")

            #切到寫信內容部分的frame

            self.driver.switch_to.frame(self.driver.find_element_by_xpath("//*[@class=‘APP-editor-iframe‘]"))

            #擷取寫信地區的元素

            editBox = wait.until(lambda x:x.find_element_by_xpath("/html/body"))

            editBox.click()

            editBox.send_keys(u‘這是夏曉旭的第一個自動化發郵件指令碼!‘)

            #切回到預設frame

            self.driver.switch_to.default_content()

            #擷取發送按鈕元素

            send=wait.until(lambda x:x.find_element_by_xpath("//*[@class=‘jp0‘]//*[@role=‘button‘]//*[.=‘發送‘]"))

            send.click()

        except TimeoutException, e:

            # 捕獲TimeoutException異常

            print traceback.print_exc()

        except NoSuchElementException, e:

            # 捕獲NoSuchElementException異常

            print traceback.print_exc()

        except Exception, e:

            # 捕獲其他異常

            print traceback.print_exc()

 

if __name__ == ‘__main__‘:

    unittest.main()

 

python webdriver 登陸163郵箱給QQ郵箱發送一個郵件,顯示等待

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.