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. MYSQL 自定义序列函数

    代码如下: DROP TABLE SEQNUM; -- 创建序列表 CREATE TABLE SEQNUM( ID BIGINT ); -- 插入初识值 insert INTO SEQNUM valu ...

  2. 初识python:time 模版

    语法及示例代码如下: import time # time 时间戳,1970年到当前时间的秒数 print('time:',time.time()) # sleep 延时.睡眠(s) print('s ...

  3. 公网ip定位原理-心得

    1.前言 正在做一个根据公网ip来定位到大体的位置,一般是精确到城市或地区, 如果想要精确到街道和地图一一对应,那得使用GPS才可以,这里不讨论. 2.科普 公网也就是外网,由运营商的机房服务器自动给 ...

  4. vue3+vant h5: Rem 移动端布局适配之postcss-pxtorem和lib-flexible

    如果不引入插件的话:ui稿的px转化成rem需自己计算 根据设计稿我们需要自己计算元素的rem(假如我们将html根元素font-size设置为41.4px): 那么1rem=41.4px; ui稿上 ...

  5. 【Java】代码块

    代码块 代码块的作用:用来初始化类.对象 代码块如果有修饰的话,只能使用static 分类:静态代码块.非静态代码块 静态代码块 static{ } 内部可以有输出语句 随着类的加载而执行,而且只执行 ...

  6. Ubuntu 18.04 server安装+搭建Seacms v10.1网站

    0x00 写在前面 以前我天真的认为,ubuntu Desktop会安装了,server就无所谓了,其实完全不然,server还是有一些坑点的. 之所以选择Seacms搭建网站,是因为这个SeaCMS ...

  7. F2BPM的流程仿真

    仿真概述 F2BPM工作流仿真是一种通过建立工作流虚拟运行环境执行工作流仿真的方法.集中式仿真引擎解释工作流仿真模型,仿真活动的执行,处理仿真过程中的不确定性,从而完成工作流模型的仿真.同时,会实时显 ...

  8. 【刷题-LeetCode】236. Lowest Common Ancestor of a Binary Tree

    Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) o ...

  9. thanos的日志能不能打到文件里面去?

    不行. thanos/pkg/logging/logger.go: logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) if logF ...

  10. centos6下php53升级为php7

    1.查看版本 [root@web-1 blog]# php -v No log handling enabled - turning on stderr logging Created directo ...