• 随笔: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()
    
    
    
    
  • 相关阅读:
    POJ 2594 Treasure Exploration(最大路径覆盖)
    POJ 2516 Minimum Cost(最小费用最大流)
    城市面积
    python strip()函数
    python sys.path.append
    python调用shell,python与shell间变量交互
    远程登陆强大命令screen
    pythonLevenshtein几个计算字串相似度的函数解析
    python 程序bug解决方案
    python 全局变量
  • 原文地址:https://www.cnblogs.com/caodingzheng/p/14007089.html
Copyright © 2020-2023  润新知