P155——创建测试用例
  1. 录制脚本
  2. 编辑脚本
  3. 定位辅助
P159——Selenium IDE 命令
在浏览器中打开URL,可以接受相对路径和绝对路径两种形式
open
open(url)
 
单击链接、按钮、复选框和单选框
click(elementLocator)
 
模拟键盘的输入,向指定的input中输入值
type(inputLocator,value)
 
根据optionSpecifier选项选择器来选择一个下拉菜单选项
select(dropDownLocator,optionSpecifier)
 
模拟单击浏览器的后退按钮
goBack()
 
选择一个弹出窗口
select(windowId)
 
根据指定时间暂停Selenium脚本执行
pause(millisenconds)
 
模拟页面元素事件被激活的处理动作
fireEvent(elementLocatore,evenName)
 
模拟单击浏览器关闭按钮
close
 
P162——断言与验证
P167——等待与变量
 
 
1、启用火狐插件Selenium IDE

2、点击红点进行脚本录制
3、使用Selenium IDE导出脚本,选择导出Python语言的脚本

 
4、在命令行中运行该脚本,报错。这是因为Python文件在第10行没有类名导致

5、导出脚本的源码如下,添加一个hello类名,再运行
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
 
class hello(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True
 
def test_(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("kw").click()
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys(u"你好")
driver.find_element_by_id("su").click()
 
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
 
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
 
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
 
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
 
if __name__ == "__main__":
unittest.main()
运行成功:

 
 

虫师Selenium2+Python_6、Selenium IDE的更多相关文章

  1. Web自动化Selenium2环境配置中Selenium IDE的安装

    下载的firefox32.0的版本,但是在附件组件中只有selenuim IDE button,本以为这个就是selenium IDE插件,自以为是的后果就是把自己坑了.并且像一些selenium I ...

  2. Postman和Selenium IDE开局自带红蓝BUFF属性,就问你要还是不要

    话不多说,下面给大家介绍两款工具,selenium IDE和Postman. 为什么说是自带红蓝Buff,因为想做UI自动化和接口自动化的同学,很多时候,都难在了开头. 比如你要学习语言,你要学习框架 ...

  3. Selenium IDE环境部署

    摘自https://blog.csdn.net/ywyxb/article/details/59103683 Selenium IDE环境部署 - Firefox浏览器 Firefox-ESR版本下载 ...

  4. Selenium IDE安装及环境搭建教程

    摘自https://blog.csdn.net/ywyxb/article/details/59103683 Selenium IDE环境部署- Firefox浏览器Firefox-ESR版本下载(推 ...

  5. 基于webdriver的jmeter性能测试-Selenium IDE

    前言: 由于某些项目使用了WebGL技术,需要高版本的Firefox和Chrome浏览器才能支持浏览,兼容性很弱,导致Loadrunner和jmeter(badboy)无法正常进行录制脚本.因此我们采 ...

  6. Selenium IDE 基础教程

    Selenium IDE 基础教程 1.下载安装     a 在火狐浏览其中搜索附件组件,查找 Selenium IDE     b 下载安装,然后重启firefox 2.界面讲解      在菜单- ...

  7. java selenium (八) Selenium IDE 用法

    Selenium IDE 是Firefox 浏览器的一个插件, 它会记录你对Firefox的操作,并且可以回放它的操作. 用法简单,不过我觉得这个没多大的用处 阅读目录   Selenium IDE ...

  8. Selenium IDE和Selenium RC的安装

    1       安装FireBug和FirePath 1.在火狐浏览器中,点击”添加附件”按钮,弹出”附加组件管理器”页面 2.在弹出页面中,输入“fireBug”,点击“搜索”按钮,弹出fireBu ...

  9. 【Selenium】4.创建你的第一个Selenium IDE脚本

    http://newtours.demoaut.com/ 这个网站将会用来作为我们测试的网址. 通过录制来创建一个脚本 让我们来用最普遍的方法——录制来创建一个脚本.然后,我们将会用回放的功能来执行录 ...

随机推荐

  1. python使用String的Template进行参数动态替换

    1.前言: 之前使用string的find(),从指定的param里面查找,是否包含了某个字符,有的话,使用replace进行替换,一个接口的param要替换的参数少的话,使用这种方式,的确可行,如果 ...

  2. 更加高效的遍历 Map

    https://stackoverflow.com/questions/46898/how-do-i-efficiently-iterate-over-each-entry-in-a-java-map ...

  3. Linux下配置GitHub

    一.注册GitHub账号 二.在linux命令行输入 git config --global user.name "YOUR NAME" #配置github账号 git confi ...

  4. Echart可视化学习(七)

    文档的源代码地址,需要的下载就可以了(访问密码:7567) https://url56.ctfile.com/f/34653256-527823386-04154f 正文: 官网找到类似实例, 适当分 ...

  5. Genymotion安装apk问题

    Genymotion安装apk时,出现如下错误: 问题原因分析:很多apk使用arm架构的 cpu,在x86上安装会存在问题. 解决办法: 在Genymotion模拟器上安装一个能够解析ARM架构的a ...

  6. 【解决了一个小问题】golang protocol buffers 3中去掉json标签中的omitempty

    参考了这篇帖子:golang protobuf从生成的json标记中删除omitempty标记 由于是在windows上开发,因此写了一个python脚本来解决: remove_tag.py impo ...

  7. Cesium中文网——如何开发一款地图下载工具[一]

    Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ Cesium中文网的朋友们的其中一个主题是:自己独立开发一款地图 ...

  8. 春节将至,喜庆的烟花安排上(js实现烟花)

    一年一度的春节即将来临,然后苦逼的我还在使劲的摸鱼,未能回家体验小时候路边放爆竹的快乐时光,所以只能在网上来实现这个小小的心愿了.烟花静态效果图如下: 为了大伙复制方便就不分开写,直接复制即可,具体实 ...

  9. C#8.0 可空引用类型

    介绍 我们的项目代码运行时最频繁的错误之一就是 System.NullReferenceException 异常,c#8.0增加的可为空引用类型就是用来帮助开发者降低甚至消除NULL异常.我们需要注意 ...

  10. golang操作mysql

    1. 安装mysql驱动库和sqlx基于官方sql库的扩展库 go get github.com/go-sql-driver/mysql go get github.com/jmoiron/sqlx ...