zoukankan      html  css  js  c++  java
  • 随笔:python+selenium+unittest用qq邮箱上传文件并发送邮件

    随笔:python+selenium+unittest用qq邮箱上传文件并发送邮件

    #coding = utf-8
    
    import unittest
    from selenium import webdriver
    from time import sleep
    
    
    class qqemail(unittest.TestCase):
        def setUp(self):
            print("调用qq邮箱发送邮件")
    
        def testEmail(self):
            # 屏蔽自动化受控提示 && 开发者提示
            self.option = webdriver.ChromeOptions()
            self.option.add_experimental_option("excludeSwitches", ['enable-automation', 'load-extension'])
            # 屏蔽'保存密码'提示框
            self.prefs = {}
            self.prefs["credentials_enable_service"] = False
            self.prefs["profile.password_manager_enabled"] = False
            self.option.add_experimental_option("prefs", self.prefs)
            # 打开谷歌浏览器
            self.driver = webdriver.Chrome(options=self.option)
            # 窗口最大化
            self.driver.maximize_window()
            sleep(5)
            self.driver.get("https://mail.qq.com")
            sleep(5)
            self.driver.switch_to.frame('login_frame')
            sleep(2)
            self.driver.find_element_by_css_selector("a#switcher_plogin").click()
            sleep(2)
            self.driver.find_element_by_xpath("//input[@id='u']").send_keys("username")
            self.driver.find_element_by_css_selector("input#p").send_keys("password")
            self.driver.find_element_by_css_selector("input.btn").click()
            sleep(5)
            self.driver.find_element_by_xpath("//a[text()='写信']").click()
            sleep(5)
            self.driver.switch_to.frame('mainFrame')
            print(self.driver.find_element_by_xpath("//a[@id='to_btn']").text)
            #print(self.driver.find_element_by_css_selector("a#to_btn").text)
    
            self.driver.find_element_by_css_selector("div#toAreaCtrl>div>input.js_input").send_keys("收件人邮箱")
            sleep(2)
            self.driver.find_element_by_xpath("//div[@class='div_txt']//input[@id='subject']").send_keys("测试邮件发送")
            #上传附件
            self.driver.find_element_by_xpath("//div[@class='input_title']//input[@type='file']").send_keys(r'G:pythonjbcloudAItest	estrunner	est测试报告1.html')
            sleep(10)
            self.driver.find_element_by_css_selector("a[name='sendbtn']").click()
            sleep(5)
            t1 = self.driver.find_element_by_css_selector("b#sendinfomsg").text
            print(t1)
            sleep(1)
            self.assertEqual("您的邮件已发送",t1)
            sleep(2)
    
    
        def tearDown(self):
            print("邮件发送完成")
            self.driver.quit()
    
        if __name__ == '__main__':
            unittest.main()
    
    
    
    
  • 相关阅读:
    Leetcode 204. Count Primes
    Leetcode 263. Ugly Number
    Leetcode 202. Happy Number
    Leetcode 258. Add Digits
    Leetcode 23. Merge k Sorted Lists
    BAT 批处理脚本教程
    入门训练 序列求和
    JAVA学习:方法
    大小之差
    java中length,length(),size()区别
  • 原文地址:https://www.cnblogs.com/caodingzheng/p/14007089.html
Copyright © 2011-2022 走看看