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

#练习:登录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

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

[Python爬虫] Selenium实现自动登录163邮箱和Locating Elements介绍

目录(?)[+] 前三篇文章介绍了安装过程和通过Selenium实现访问Firefox浏览器并自动搜索"Eastmount"关键字及截图的功能.而这篇文章主要简单介绍如何实现自动登录163邮箱,同时继续介绍Selenium+Python官网Locating Elements部分内容.        希望该篇基础性文章对你有所帮助,如果有错误或不足之处,请海涵~        [Python爬虫] 在Windows下安装PhantomJS和CasperJS及入门介绍(上)        

5、Selenium+Python自动登录163邮箱发送邮件

1.Selenium实现自动化,需要定位元素,以下查看163邮箱的登录元素 (1)登录(定位到登录框,登录框是一个iframe,如果没有定位到iframe,是无法定位到账号框与密码框) 定位到邮箱框(name='email') 定位到密码框(name='password') 定位到登录按钮(id="dologin") 2.代码实现 #coding=utf-8 import time from selenium import webdriver broswer = webdriver.I

[转][Python][自动登录163邮箱]

#-*- coding:UTF-8 -*-import urllib,urllib2,cookielibimport xml.etree.ElementTree as etree #xml解析类 class Login163:   #伪装browser    header = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}    us

Page Object实例(一) - Java + Selenium 登录163邮箱

Page Object 是什么: Page Object是Selenium2开始提供的一种代码设计模式. 其核心思想是把web页面的元素查找及操作和页面测试分离开. 这样之后的更新和维护中如果有页面元素变动, 不需要修改测试类, 只要修改其对应的页面元素的查找代码即可. 登录163邮箱的实例包括: 其中: 1. LoginPage.java 是主要测试页面, 包括查找元素, 操作元素实现登录 2. HomePage.java 是登录成功后会跳转到的页面, 在此用来作为登录操作方法的返回值及拿个元

python2+selenium+mail,自动登录126邮箱

在进行登录126邮箱时有几个坑,要完美避过可以看一下下文,直接上代码: #encoding = utf-8 from selenium import webdriverimport unittestimport timeclass login126(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome(executable_path = "chromedriver") def test_login(sel

登录163邮箱发邮件

#encoding=utf-8 from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By #打开浏览器 driver = webdriver.

python webdriver 显示等待-自动登录126邮箱,添加联系人

脚本内容:#encoding=utf-8#author-夏晓旭from selenium import webdriverimport timefrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.common.exceptions import TimeoutException, NoSuchElementExceptioni

selenium2+python3登录163邮箱

首先查看页面的整个登录流程: 打开mail.163.com→点击邮箱账号登录→账号输入框→密码输入框→登录 一.单一流程实现:打开网页,找到邮箱账号登录,输入账号密码,登录 # 导入webdriver驱动 from selenium import webdriver from time import ctime # 新建火狐浏览器驱动 dr = webdriver.Firefox() dr.get('https://mail.163.com') # 点击邮箱账号登录,使用xpath定位 dr.f

python webdriver firefox 登录126邮箱,先添加联系人,然后进入首页发送邮件,带附件。

代码:#encoding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_condition