selenium项目实战--126邮箱的登录和发送邮件

import unittest
from selenium import webdriver
import time
from ddt import ddt, data, unpack


@ddt
class EmailTest(unittest.TestCase):
    @classmethod
    def setUpClass(self) -> None:
        self.driver = webdriver.Chrome()
        self.driver.get('https://mail.126.com/')
        self.driver.implicitly_wait(10)

    @classmethod
    def tearDownClass(self) -> None:
        self.driver.quit()

    @data(('126账号', '126密码'))
    @unpack
    def test_1_login_email(self, user, pwd):
        iframe = self.driver.find_element_by_xpath('//iframe[starts-with(@id,"x-URS-iframe")]')
        self.driver.switch_to.frame(iframe)
        self.driver.find_elements_by_xpath('//input[starts-with(@id, "auto-id-")]')[0].send_keys(user)
        self.driver.find_elements_by_xpath('//input[starts-with(@id, "auto-id-")]')[1].send_keys(pwd)
        self.driver.find_element_by_css_selector('#un-login').click()
        time.sleep(2)
        self.driver.find_element_by_css_selector('#dologin').click()
        time.sleep(2)

    @data(('目标邮箱', 'python测试用例', '这是一条测试用例'))
    @unpack
    def test_2_write_letter(self, receiver, title, content):
        self.driver.find_element_by_xpath('//*[@id="_mail_component_132_132"]').click()
        time.sleep(2)
        self.driver.find_element_by_xpath('//*[starts-with(@id, "_mail_emailtips_")]').click()
        time.sleep(1)
        self.driver.find_element_by_xpath('//input[@class="nui-editableAddr-ipt"]').send_keys(receiver)
        self.driver.find_element_by_xpath('//*[contains(@id, "_subjectInput")]').send_keys(title)
        iframe = self.driver.find_element_by_xpath('//*[starts-with(@id, "_mail_editor")]/div[1]/div[2]/iframe')
        self.driver.switch_to.frame(iframe)
        self.driver.find_element_by_css_selector('body').send_keys(content)
        time.sleep(2)
        self.driver.switch_to.default_content()
        self.driver.find_element_by_xpath('//footer/div[1]/span[2]').click()
        time.sleep(2)


if __name__ == '__main__':
    unittest.main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值