selenium常用的API(一)截屏
我们在使用selenium测试过程中,可使用截屏功能将用例执行失败的画面截图保存,方便测试执行结束后查看并定位问题。
以下介绍两种截屏方法:
对当前浏览器窗口截屏
使用selenium自带的get_screenshot_as_file()方法
截图成功后返回True,如果发生了IOError异常,会返回False。
# encoding=utf-8
import unittest
import time
from selenium import webdriver class VisitSogouByIE(unittest.TestCase):
def setUp(self):
# 启动IE浏览器
#self.driver=webdriver.Firefox(executable_path="e:\\geckodriver")
self.driver = webdriver.Ie(executable_path="d:\\driver\IEDriverServer") def test_captureScreenInCurrentWindow(self):
url = "http://www.sohu.com"
# 访问搜狐首页
self.driver.get(url)
try:
'''
调用get_screenshot_as_file(filename)方法,对浏览器当前打开页面
进行截图,并保为G盘下的screenPicture.png文件。
'''
result=self.driver.get_screenshot_as_file(r"g:\screenPicture.png")
print result
except IOError, e:
print e def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()
使用PIL模块调用操作系统API截桌面全屏
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了。PIL功能非常强大,但API却非常简单易用。
PIL非python内置模块,使用前需先安装PIL安装包→ pip install PIL
from PIL import ImageGrab
im=ImageGrab.grab()
im.save("1.jpg","jpeg")
要想了解PIL的更多使用,参请见:https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00140767171357714f87a053a824ffd811d98a83b58ec13000
selenium常用的API(一)截屏的更多相关文章
- selenium常用的API
打开浏览器 driver.get("http://www.baidu.com") 最大化浏览器 driver.maximize_window() 关闭浏览器 driver.quit ...
- VB用API模拟截屏键PrintScreen
很多人用 SendKeys "{PRTSC}" 模拟截屏键 PrintScreen 的时候提示<错误:'70' 拒绝的权限>,于是经常遇到人问...干脆写下来 '声明 ...
- selenium常用的API(七)判断元素是否可见
web页面不可见的元素虽不在页面上显示,但是存在于DOM树中,这些元素webdriver也能找到. element.is_displayed()方法可以判断元素是否在页面上显示,如果显示返回True, ...
- Java编程语言下Selenium 利用Robot自己编写截屏方法
import java.awt.Robot; import java.awt.event.KeyEvent; import java.util.concurrent.TimeUnit; import ...
- selenium常用的API(六)浏览器窗口切换
当使用selenium webdriver进行自动化测试打开多个窗口的时候,可能需要在不同的窗口间进行切换,webdriver提供的获取浏览器窗口句柄.切换句柄的方法如下: 获取当前窗口句柄 driv ...
- selenium常用的API(五)获取title、刷新、前进和后退
获取网页title的属性值 #encoding=utf-8 from selenium import webdriver import unittest import time class Visit ...
- selenium常用的API(四)设置get方法最大加载时间
我们在进行自动化测试的时候,使用get方法打开页面时会等到页面完全加载完才会执行后续操作, 有时我们需要的元素已加载完成,而部分JS未加载完导致加载时间很长,这无疑增加了自动化测试的时间, 针对此情况 ...
- selenium常用的API(三)获取网页title、html源码
获取网页title 获取页面title的方法可以直接用driver.title获取到,然后可以把获取到的结果用做断言. #encoding=utf-8 from selenium import web ...
- selenium常用的API(二)浏览器窗口设置
浏览器窗口最大化 # encoding=utf-8 from selenium import webdriver driver = webdriver.Ie(executable_path=" ...
随机推荐
- maven项目打包跳过单元测试
在pom.xml中添加一下代码: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifact ...
- Java程序运行机制
Java程序运行机制 编译型(compile) 它有一个负责翻译的程序(编译器),将我们写的 Java 源代码转为计算机可执行的代码 举个例子:把一本中文书翻译成英文书 应用:操作系统.C.C++ 解 ...
- POJ 1941 The Sierpinski Fractal
总时间限制: 1000ms 内存限制: 65536kB 描述 Consider a regular triangular area, divide it into four equal triangl ...
- appium通过index查找目标控件
2.1 通过判断控件属性获取控件 控件的所有属性都可以用作判断,比如它的text,index,resource-id是否clickable等,例如: 2.1.1 通过文本查找目标控件 1 2 el = ...
- testNG的安装
1,testNG介绍 TestNG ( Testing Next Generation ,下一代测试技术) testNG的强大之处在于它是 利用注释(注解) 来强化测试功能的测试框架,可以用来做接口测 ...
- urlencode编码 — 为什么要编码
原文链接:https://blog.csdn.net/stpeace/article/details/82892571 参考:https://blog.csdn.net/z69183787/artic ...
- 《TCP/IP - OSI和TCP/IP分层模型》
一:分层模型 - - OSI 更强调:通信协议必要的功能是什么 - TCP/IP 更强调:在计算机上实现协议应该开发哪种程序 二:为什么会产生协议标准化 (分层模型的产生)? - 由于各个厂商生产 ...
- Ubuntu19.04 Help
Ubuntu Dock 为应用程序启用最小化操作,立即生效. $ gsettings set org.gnome.shell.extensions.dash-to-dock click-action ...
- 20 IO流(十七)——Commons工具包,FileUtils(二)——copy方法
copy方法 package com.sxt.copy; import java.io.File; import java.io.IOException; import java.net.URL; i ...
- 小程序发起get请求====post请求