Selenium Python自动化测试学习知识积累-操作iframe富文本框
2017-12-26 16:19
351 查看
1、打开htpp://mail.sohu.com
2、输入用户名
3、输入密码
4、点击登录按钮
5、点击“写邮件”按钮
6、输入收件人
7、输入邮件标题
8、输入邮件正文内容
9、点击发送按钮
2、输入用户名
3、输入密码
4、点击登录按钮
5、点击“写邮件”按钮
6、输入收件人
7、输入邮件标题
8、输入邮件正文内容
9、点击发送按钮
# encoding=utf-8 from selenium import webdriver import unittest import time import traceback from selenium.common.exceptions import TimeoutException, NoSuchElementException from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as ec class TestDemo(unittest.TestCase): def setUp(self): # 创建存储自定义文件配置文件的路劲变量 propath = "C:\\Users\\ifthink\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xf1mvsab.default" # 加载自定义配置文件到firefoxprofile实例中 profile = webdriver.FirefoxProfile(propath) # 启动带自定义配置文件的浏览器 self.driver = webdriver.Firefox(executable_path="F:\\Python\\Webdriver\\geckodriver.exe", firefox_profile = profile) def test_sohumailsendmail(self): url = "http://mail.sohu.com" # 访问首页 self.driver.get(url) try: wait = WebDriverWait(self.driver, 10) wait.until(ec.element_to_be_clickable((By.XPATH, "//input[@placeholder='请输入您的邮箱']"))) username = self.driver.find_element_by_xpath("//input[@placeholder='请输入您的邮箱']") username.clear() username.send_keys("xxxx@sohu.com") password = self.driver.find_element_by_xpath("//input[@placeholder='请输入您的密码']") password.clear() password.send_keys("xxxxxx") login = self.driver.find_element_by_xpath("//input[@value='登 录']") login.click() wait.until(ec.element_to_be_clickable((By.XPATH, "//li[text()='写邮件']"))) self.driver.find_element_by_xpath("//li[text()='写邮件']").click() time.sleep(2) receiver = self.driver.find_element_by_xpath("//div[@arr='mail.to_render']//input") # 输入收件人 receiver.send_keys("ifthink@sohu.com") subject = self.driver.find_element_by_xpath("//input[@ng-model='mail.subject']") # 输入邮件标题 subject.send_keys("这是一封测试邮件") # 获取邮件正文编辑区域的iframe页面元素对象 iframe = self.driver.find_element_by_xpath("//iframe[contains(@id,'ueditor_0')]") # 通过switch_to.frame()方法切换进入富文本框 self.driver.switch_to.frame(iframe) # 获取富文本框中编辑页面元素对象 editbox = self.driver.find_element_by_xpath("//html/body") editbox.send_keys("邮件的正文内容") # 跳出富文本框 self.driver.switch_to.default_content() # 找到发送按钮,并点击它 self.driver.find_element_by_xpath("//span[text()='发送']").click() # 显示等待含有关键字串“发送成功”的页面元素出现在页面中 wait.until(ec.visibility_of_element_located((By.XPATH, "//span[.='发送成功']"))) print("邮件发送成功") except TimeoutException: print("显示等待页面元素超时") except NoSuchElementException: print("寻找的页面元素不存在") except Exception: print(traceback.print_exc()) if __name__ == '__main__': unittest.main()
相关文章推荐
- Tomcat学习 解析 积累知识集锦
- JQuery学习过程小知识积累
- linux驱动学习知识积累
- JNI学习积累之三 ---- 操作JNI函数以及复杂对象传递
- vc知识积累(2.操作Excel数据库)
- 学习Bootstrap知识记录点-----标签操作
- 黑马程序员--IO流和文件操作--java学习日记8(基础知识)
- 数据库知识学习--DML操作(一)
- 知识学习——jQuery文档操作
- 2015年1月6日从今天起我定记录一下我自己的学习成果,知识的积累从一点一滴开始!window下搭建solr
- java学习知识积累-Mybatis中Mapper内置方法细解
- 2015年1月9日从今天起我定记录一下我自己的学习成果,知识的积累从一点一滴开始!window下搭建solr
- MySQL的日志基础知识及基本操作学习教程
- 学习Bootstrap知识记录点-----分页操作
- c语言学习之基础知识点介绍(十九):内存操作函数
- 系统学习jQuery.核心知识.局部.jQuery操作.DOM操作.删除节点
- JNI学习积累之三 ---- 操作JNI函数以及复杂对象传递
- 自己常用的linux操作指令,学习中,积累中
- 【知识积累】Entity Framework学习:POCO延迟加载