【基础】练习册45-Python3_selenium_搜索邮件
代码如下:
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest,time
from public import login #导入login文件
class TestSendEmail(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
#self.driver.implicitly_wait(20)
self.base_url = "https://mail.163.com/"
self.verificationErrors = []
#只输入收件人发送
def test_search(self):
driver = self.driver
driver.get(self.base_url)
#登录
login.login(self,'alyna_cai','QQqq1122369')
time.sleep(2)
#s搜索邮件
driver.find_element_by_xpath('//*[@class="tY0"]/div/div/input').send_keys(u'豆豆')
driver.find_element_by_xpath('//*[@class="tY0"]/div/div/input').send_keys(Keys.ENTER)
time.sleep(3)
#断言搜索结果---定位不到搜索结果路径
text = driver.find_element_by_xpath('//div[@class="tb0"]/div/h1').text
#print(text)
self.assertEqual(text,u"搜索结果")
#time.sleep(2)
login.logout(self)
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == "__main__":
unittest.main()