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 DataFrame to_sql方法插入日期或时间类型的数据时 报ORA-01861 文字与字符串不匹配 的解决方法

    业务团队近期提出一个需求: 希望在接口调用之前先批量插入Excel中的数据作为数据预置 这个需求以前已经开发完成 本来以为可以很快调试完毕 没成想遭遇一个难关 DataFrame.to_sql方法在执 ...

  2. python与redis交互(4)

    python可以使用redis模块来跟redis交互 redis模块的使用 安装模块: pip3 install redis 导入模块:import redis 连接方式 严格连接模式:r=redis ...

  3. Centos7安装maxscale 实现mysql的读写分离

    安装依赖 yum install -y novacom-server.x86_64 libaio.x86_64 libaio-devel.x86_64 网站下载 https://downloads.m ...

  4. spring security 自动登录 --- 心得

    1.前言 仍然是使用cookie存储登录数据,但是存储的数据 由 spring security自动创建 ,当登出后自动删除cookie, 如果不登出也仍在生命周期内,关闭浏览器再打开将会自动登录,无 ...

  5. Linux上天之路(三)之Linux系统目录

    1. Linux设计思想 1) 程序应该小而专一,程序应该尽量的小,且只专注于一件事上,不要开发那些看起来有用但是90%的情况都用不到的特性: 2) 程序不只要考虑性能, 程序的可移植性更重要,she ...

  6. 本地Java大数据环境基础配置(Maven)

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6812623309138559500/ 创建项目 准备pom.xml文件配置(附在文档最后) 在下载jar过程中极其 ...

  7. json 转换C# class(用于对接api

    //说明//使用场景:对接api,返回json结果,直接转换C# class//如何使用:复制下面js代码在浏览器控制台执行 ` "order_item_id": "28 ...

  8. 【刷题-LeetCode】275. H-Index II

    H-Index II Given an array of citations sorted in ascending order (each citation is a non-negative in ...

  9. 【VictoriaMetrics】vm单机版和vm-storage的查询功能的对比

    1.vm-storage源码调用表 文件 行号 函数 说明 app/vmstorage/main.go 53 main 入口94行调用srv.RunVMSelect() app/vmstorage/t ...

  10. unity3d,java,c#,python,rospy的socket通信测试

    1.C#在与其他人通信时,最好不要用tcpclient来承接其他语言,会收不到用户名,最好都用socket. 2.unity3d在与java通信时,对方返回我unity3d发的数据流会打印收到一个类, ...