import time
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.keys import Keys
from getpass import getpass def run():
driver.get(url='https://mail.qq.com/')
# 遇到iframe,需要切换
iframe_list = driver.find_elements_by_tag_name('iframe')
# print(iframe_list)
driver.switch_to.frame(iframe_list[]) # 输入用户名、密码并登录
driver.find_element_by_class_name('inputstyle').send_keys(user)
driver.find_element_by_class_name('password').send_keys(pwd)
driver.find_element_by_class_name('password').send_keys(Keys.ENTER)
# 点击写信
driver.find_element_by_id('composebtn').click()
iframe = driver.find_element_by_id('mainFrame')
driver.switch_to.frame(iframe)
# 输入收件人、主题信息
driver.find_element_by_xpath('//*[@id="toAreaCtrl"]/div[2]/input').send_keys(to)
driver.find_element_by_xpath('//*[@id="subject"]').send_keys(theme) # 遇到body iframe
iframe_body = driver.find_element_by_class_name('qmEditorIfrmEditArea')
driver.switch_to.frame(iframe_body)
# 输入文本
driver.find_element_by_tag_name('body').send_keys(content)
# 切出body iframe
driver.switch_to.default_content()
driver.switch_to.frame(iframe)
# 点击发送按钮
driver.find_element_by_xpath('//*[@id="toolbar"]/div/a[1]').click()
# time.sleep()
# driver.quit() if __name__ == '__main__':
to = '' # 你想发的邮箱
theme = 'python自动发送邮件'
content = '不用回,我就试试,哈哈哈。'
user = '' # QQ账号
pwd = getpass('密码:') # QQ密码 # 创建 option 对象
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# 创建浏览器对象
driver = webdriver.Chrome(options=option)
  '''
  driver = webdriver.Chrome(executable_path=r'E:\chromedriver.exe')
  '''
driver.implicitly_wait()
run()

python+selenium 发送邮件的更多相关文章

  1. python+selenium 自动化测试实战

    一.前言: 之前的文章说过, 要写一篇自动化实战的文章, 这段时间比较忙再加回家过11一直没有更新博客,今天整理一下实战项目的代码共大家学习.(注:项目是针对我们公司内部系统的测试,只能内部网络访问, ...

  2. web自动化 基于python+Selenium+PHP+Ftp实现的轻量级web自动化测试框架

    基于python+Selenium+PHP+Ftp实现的轻量级web自动化测试框架   by:授客 QQ:1033553122     博客:http://blog.sina.com.cn/ishou ...

  3. python+selenium封装UI自动化框架

    seleinum框架 框架的思想:  解决我们测试过程中的问题:大量的重复步骤,用自动化来实现    1)配置和程序的分离    2)测试数据和程序的分离    3)不懂编程的人员可以方便使用:使用的 ...

  4. python+selenium 浏览器的问题

    以前用selenium调用firefox是不需要驱动的,最近安装了python3.52+最新的firefox 发现调不起来了 搜索以后发现Firefox 47+需要搞个firefox的驱动 gecko ...

  5. 一次完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试

    Web登录测试是很常见的测试!手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文作者就用python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动 ...

  6. Python + Selenium 实现登录Office 365

    最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...

  7. python+selenium+Robot

    准备工作: 1.下载python2.7 http://python.org/getit/ 2.下载下载setuptools [python 的基础包工具] 可以帮助我们轻松的下载,构建,安装,升级,卸 ...

  8. python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...

  9. Functional testing - python, selenium and django

    Functional testing  - python selenium django - Source Code : from selenium import webdriverfrom sele ...

随机推荐

  1. PHP 获取一周的时间

    $date = array( 'Monday' => array(date('Y-m-d H:i:s',strtotime("Monday")),date('Y-m-d H: ...

  2. Liunx 如何查看80端口被哪个程序所占用

    场景:启服务时一直报80端口被占用 解决方: 1.首先查看下 80 端口的使用情况 netstat -anp|grep 80 查看80端口被被占用的PID 2.根据这个PID 来查看被哪个程序在使用 ...

  3. 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...

  4. Calendar 时间类的应用

    Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法却遭到众多批评,不建议使用,更推荐使用 Calendar 类进行时间和日期的处 ...

  5. Codeforces 1296E2. String Coloring (hard version)

    这道题和HDU1257一模一样,一开始窝都用贪心直接解,没法理解为什么求一个最长下降序列,直到看了巨巨的题解,先给出一个定理,Dilworth's theorem,离散学不好,补题两行泪,该定理是说, ...

  6. window进行缩放时左侧菜单高度随之变化

    window.onresize = function(){ $(); }

  7. (译)Calculus on Computational Graphs: Backpropagation

    Posted on August 31, 2015 Introduction Backpropagation is the key algorithm that makes training deep ...

  8. python编写banner获取的常用模块

    模块的概念:模块也叫库,每个模块中都内置了大量的功能和函数.类和变量.它就像是积木,可以根据需要进行调用组合.模块就是程序,每个模块就是一个后缀为.py的Python程序.Python的模块分为标准模 ...

  9. Ubuntu系统部署tomcat并启用JMX实战案例

    Ubuntu系统部署tomcat并启用JMX实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装JDK环境 1>.更换阿里云的软件源 [root@zabbix_g ...

  10. windows目标进程注入dll

    在别的程序注入dll 步骤: ,获取目标进程ID,CreateToolhelp32Snapshot()函数; ,获取目标进程句柄,OpenProcess()函数; ,目标进程要一块内存,Virtual ...