码迷,mamicode.com
首页 > Web开发 > 详细

【webdriver自动化】使用unittest实现自动登录163邮箱然后新建一个联系人

时间:2018-06-25 01:17:38      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:from   tab   https   page   ble   condition   use   handle   pat   

#练习:登录163邮箱然后新建一个联系人
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class AddEmailContactByFireFox(unittest.TestCase):

    def setUp(self):
        self.driver =webdriver.Ie(executable_path="c:\\IEDriverServer")
        
    def test_HandleFrameByPageSource(self):
        url = "https://mail.163.com/"
        self.driver.get(url)
        time.sleep(2)
        iframe=self.driver.find_element_by_xpath("//iframe[@id=‘x-URS-iframe‘]")  
        self.driver.switch_to.frame(iframe)   

        time.sleep(5)
        user_name = self.driver.find_element_by_xpath(".//input[@name=‘email‘]")
        pwd = self.driver.find_element_by_xpath(".//input[@name=‘password‘]")
        login = self.driver.find_element_by_xpath("//a[@id=‘dologin‘]")

        user_name.clear()
        pwd.clear()
        user_name.send_keys("XXX")
        pwd.send_keys("wangjing1990")
        login.click()
        time.sleep(20)


        address_link=self.driver.find_element_by_xpath(".//div[text()=‘通讯录‘]")
        address_link.click()        
        time.sleep(2)

        #wait = WebDriverWait(self.driver, 10, 0.2)
        #wait.until(EC.visibility_of_element_located((By.LINK_TEXT, "退出")))
        #assert u"退出"  in self.driver.page_source
        address_center_link=self.driver.find_element_by_xpath("//div[text()=‘通讯录‘]")
        address_center_link.click()
        time.sleep(5)

        #wait.until(EC.visibility_of_element_located((By.XPATH, "//span[text()=‘新建联系人‘]")))
        create_contact_person_button=self.driver.find_element_by_xpath("//span[text()=‘新建联系人‘]")
        create_contact_person_button.click()

        time.sleep(15)
        #name = WebDriverWait(self.driver,10).until(lambda x: x.find_element_by_xpath("//input[@id=‘input_N‘]"))
        #name.send_keys("wangjing")

        contacts_name_link=self.driver.find_element_by_xpath(".//input[@id=‘input_N‘]")
        contacts_name_link.send_keys("wangjing")       
        time.sleep(2)

        contacts_email_link=self.driver.find_element_by_xpath(".//div[@id=‘iaddress_MAIL_wrap‘]/dl/dd/div/input")
        contacts_email_link.send_keys("XXX@163.com")       
        time.sleep(2)

        contacts_tel_link=self.driver.find_element_by_xpath(".//div[@id=‘iaddress_TEL_wrap‘]/dl/dd/div/input")
        contacts_tel_link.send_keys("12345678901")       
        time.sleep(2)

        contacts_other_link=self.driver.find_element_by_xpath(".//div[@id=‘iaddress_TEL_wrap‘]/following::dl/dd/div/textarea")
        contacts_other_link.send_keys("family")       
        time.sleep(2)

        contacts_confirm_link=self.driver.find_element_by_xpath(".//span[text()=‘确 定‘]")
        contacts_confirm_link.click()       
        time.sleep(2)

    def tearDown(self):
        self.driver.quit()

if __name__ == __main__:
    unittest.main()

 

【webdriver自动化】使用unittest实现自动登录163邮箱然后新建一个联系人

标签:from   tab   https   page   ble   condition   use   handle   pat   

原文地址:https://www.cnblogs.com/jingsheng99/p/9222332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!