#练习:登录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()
原文地址:https://www.cnblogs.com/jingsheng99/p/9222332.html
时间: 2024-08-05 00:11:54