标签:quit key ace == pytho https AC python2 断言
在进行登录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邮箱
标签:quit key ace == pytho https AC python2 断言
原文地址:https://www.cnblogs.com/bettywang/p/9159684.html