python2+selenium+mail,自动登录126邮箱
Posted Python测试开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python2+selenium+mail,自动登录126邮箱相关的知识,希望对你有一定的参考价值。
在进行登录126邮箱时有几个坑,要完美避过可以看一下下文,直接上代码:
#encoding = utf-8
from selenium import webdriver
import unittest
import time
class login126(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path = "chromedriver")
def test_login(self):
self.driver.get("https://mail.126.com/")
time.sleep(3)
#此处的登录框是在iframe里,所以一定要先进入iframe,然后才能找到元素
self.driver.switch_to.frame(self.driver.find_element_by_xpath(".//*[@id=‘x-URS-iframe‘]"))
time.sleep(3)
#登录和密码输入框要切记不要用ID来进行定位,每次登录ID都会进行变化的
self.driver.find_element_by_xpath(".//*[@data-placeholder=‘邮箱帐号或手机号‘]").send_keys(‘xxxx‘)
self.driver.find_element_by_xpath(‘//*[@data-placeholder="密码"]‘).send_keys(‘xxxxx‘)
self.driver.find_element_by_xpath(‘//*[@id="dologin"]‘).click()
## self.driver.switch_to.default_content()
#断言前要等待页面加载出来后在进行断言
time.sleep(10)
assert u‘退出‘ in self.driver.page_source
def tearDown(self):
self.driver.quit()
if __name__ == ‘__main__‘:
unittest.main()
以上是关于python2+selenium+mail,自动登录126邮箱的主要内容,如果未能解决你的问题,请参考以下文章
selenium+python自动化81-html报告优化(饼图+失败重跑+兼容python2&3)