MY_使用selenium自动登录126/163邮箱并发送邮件
转自:https://www.cnblogs.com/yin-tao/p/7244082.html
我使用的是python2.7.13+selenium
ps:几天之前,我曾多次尝试写这段代码,但是在点击写信的步骤时失败了,我想我的问题应该大致是这几点:
1.写信按钮不能直接定位到,同时它的父目录id是动态的,我当时使用xpath定位到了这个动态的id,所以失败是必然的,那么就需要我们继续寻找向上寻找父目录,即多层级的xpath(建议多使用xpath/css)成功率会更高,因为层级越少,那么出现重复的可能越大(比如126写信中的主题的class和搜索框的class是一样的,当然还有很多)
2.页面的加载未完全,导致元素未找到而出现错误,所以需要我用到显示和隐式等待
3.同时要及时清除浏览器中的缓存,因为垃圾过多会导致浏览器运行变慢甚至崩溃
好了,话有点多了,直接贴代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#coding:UTF-8import timefrom selenium.webdriver.common.keys import Keysfrom selenium import webdriverdriver = webdriver.Chrome()driver.implicitly_wait(30)<br>#隐式等待,不影响用例执行速度<br>#如果登录时出现了验证码,可以将等待时长设置更长(如60),手动点击完成验证,并点击登录(ps:自动验证码很难,我感觉这种类型的验证码是其中的Boss)driver.get('http://mail.126.com/')driver.switch_to_frame('x-URS-iframe')<br>#登录页面存在iframedriver.find_element_by_name('email').clear()driver.find_element_by_name('email').send_keys('testingwtb')driver.find_element_by_name('password').send_keys('a123456', Keys.ENTER)time.sleep(6)<br>#跳转页面时,强制等待6sdriver.find_element_by_xpath("//div[@id='dvNavTop']/ul/li[2]/span[2]").click()<br>#点击写信按钮time.sleep(2)driver.find_element_by_class_name('nui-editableAddr-ipt').send_keys('780720038@qq.com')<br>#收件人driver.find_element_by_xpath("//input[@class='nui-ipt-input' and @type='text' and @maxlength='256']").send_keys(u'测试')<br>#主题xpath = driver.find_element_by_xpath("//div[@class='APP-editor-edtr']/iframe")driver.switch_to_frame(xpath)<br>#文本内容在iframe中driver.find_element_by_xpath("//body[@class='nui-scroll' and @contenteditable='true']").send_keys(u'这是一个自动化测试邮件')driver.switch_to_default_content()<br>#发送按钮在iframe外,所以需要跳出driver.find_element_by_xpath("//div[@class='nui-toolbar-item']/div/span[2]").click()<br>#发送 |
MY_使用selenium自动登录126/163邮箱并发送邮件的更多相关文章
- python selenium 多账户自动登入163邮箱
pycharm一些快捷键: ' ctrl ' +' / ' :注释 ' Tab ' :同时缩进 ' shift ' +' Tab ' :左移 一次缩进 本文webinfo.txt路径:C:\Pytho ...
- 自动化测试: Selenium 自动登录授权,再 Requests 请求内容
Selenium 自动登录网站.截图及 Requests 抓取登录后的网页内容.一起了解下吧. Selenium: 支持 Web 浏览器自动化的一系列工具和库的综合项目. Requests: 唯一的一 ...
- selenium数据驱动模式实现163邮箱的登录及添加联系人自动化操作
项目结构如下: 要求python3.0 selenium3.0 下面是代码: appModubles:addContactPersonActtion.py和LoginAction.py addCont ...
- Python+selenium自动循环扔QQ邮箱漂流瓶
Python代码如下: # coding=utf-8 from selenium import webdriver from time import sleep from random import ...
- python登录网易163邮箱,爬取邮件
from common import MyRequests,LoggerUntil,handle_exception myRequests.update_headers({ 'Accept':'tex ...
- HttpClient+jsoup登录+解析 163邮箱
找了几个,只有这个靠谱,用的是httpclient4,另外还需要commons-lang和jsoup包 http://jsoup.org/ http://www.oschina.net/code/sn ...
- phpmailer使用qq邮箱、163邮箱成功发送邮件实例代码
以前使用qq邮箱.163服务器发送邮件,帐号直接使用密码,现在不行了,得使用授权码,简单记录下 1.首先开通POP3/SMTP服务,qq邮箱——帐号——设置,找到POP3/SMTP点开启,输入短信会有 ...
- 163邮箱 SMTP发送邮件注意点
在之前163邮箱注册的时候默认开通SMTP服务的,之后需要自己手动开始. 在配置的时候服务器的地址固定 用户名称就是你的邮箱 密码需要注意的是有的是你邮箱的密码,如果不对需要填写你的授权码!
- python webdriver 显示等待-自动登录126邮箱,添加联系人
脚本内容:#encoding=utf-8#author-夏晓旭from selenium import webdriverimport timefrom selenium.webdriver.supp ...
随机推荐
- jQuery函数继承 $.extend, $.fn.extend
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LeetCode 326 Power of Three(3的幂)(递归、Log函数)
翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...
- chorme插件 ,在浏览器上模拟手机,pad 查看网页|前端技术开发必备插件
网址:http://lab.maltewassermann.com/viewport-resizer/使用方法:1在chrome浏览器上方右击,显示书签栏 2 打开插件网址,将<ignore_j ...
- 每日英语:The Most Destructive, Unpredictable Force in Tech
What's the most destructive force in the tech world, the thing that has nearly killed BlackBerry, pu ...
- 网络广告CPS/CPC/CPV/CPM/CPA分别是什么意思
CPA:注册广告(一般按用户来计算)CPC:点击广告(一般按一千个ip计算)CPS:消费广告(用户通过你的网站中投放的广告,达成消费,有提成)CPM:展示广告(展示广告,一般的视频比较多)CPV:按照 ...
- 使用PyHive操作Hive
使用PyHive操作Hive 废话 搜了一下,看到了StackOverFlow的回答,试了一下前两个方案,感觉第二个更简洁,这里记录一下,更详细的见参考. 安装依赖 pip install sasl ...
- System.in的用法
方法1 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));Scanner scanner=new Sca ...
- django中使用POST方法 获取POST数据
在django中获取post数据,首先要规定post发送的数据类型是什么. 1.获取POST中表单键值数据 如果要在django的POST方法中获取表单数据,则在客户端使用JavaScript发送PO ...
- JS 实现日期信息增加年数,月数,天数
function DateAdd(interval, number, date) { /* * 功能:实现JSScript的DateAdd功能. * 参数:interval,字符串表达式,表示要添加的 ...
- 解决opencv和mfc同时使用导致memory leak
参考资料:http://blog.csdn.net/lujin0312/article/details/42214467 最彻底的解决办法就是把用到opencv的部分做成dll,且这个dll中不出现跟 ...