from selenium import webdriver
from PIL import Image fox = webdriver.Firefox()
fox.get('http://stackoverflow.com/') # now that we have the preliminary stuff out of the way time to get that image :D
element = fox.find_element_by_id('hlogo') # find part of the page you want image of
location = element.location
size = element.size
fox.save_screenshot('screenshot.png') # saves screenshot of entire page
fox.quit() im = Image.open('screenshot.png') # uses PIL library to open image in memory left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height'] im = im.crop((left, top, right, bottom)) # defines crop points
im.save('screenshot.png') # saves new cropped image

How to take partial screenshot with Selenium WebDriver in python的更多相关文章

  1. Selenium WebDriver(Python)API

    1.通过示例介绍Selenium-WebDriver 一个简单的入门方法就是这个例子,它在Google上搜索术语“Cheese”,然后将结果页面的标题输出到控制台. java csharp pytho ...

  2. Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)

            研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...

  3. selenium webdriver+windows+python+chrome遇见的问题

    win7系统,在python中调用ChromeDriver 一直报错 “ selenium.common.exceptions.WebDriverException: Message: 'Chrome ...

  4. python + selenium webdriver 通过python来模拟鼠标、键盘操作,来解决SWFFileUpload调用系统底层弹出框无法定位问题

    Webdriver是基于浏览器操作的,当页面上传文件使用的是flash的控件SWFFileUpload调用的时候,调用的是系统底层的文件选择弹出框 这种情况,Webdriver暂时是不支持除页面外的其 ...

  5. selenium webdriver 右键另存为下载文件(结合robot and autoIt)

    首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...

  6. selenium webdriver学习(一)

    package baidu; import java.io.File; import java.io.IOException; import junit.framework.TestCase; imp ...

  7. selenium webdriver (python) 第一版PDF

    前言 如果你是一位有python语言基础的同学,又想通过python+ selenium去实施自动化,那么你非常幸运的找到了这份文档,我也非常荣幸能为你的自动化学习之路带来一丝帮助. 其实,我在sel ...

  8. [selenium webdriver Java]元素定位——findElement/findElements

    策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver ...

  9. selenium webdriver python 元素定位

    总结   定位查找时,返回查找到的第一个match的元素.如果找不到,则 raise NoSuchElementException   单个元素定位: find_element_by_idfind_e ...

随机推荐

  1. XML简介

    xml的简介(了解) * eXtensible Markup Language:可扩展标记型语言                       ** 标记型语言:html是标记型语言          ...

  2. VFP笔记

    1.计算圆的面积的计算器 650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/12/43/wKiom1MAsFzxm ...

  3. jexus防止产生 *.core文件

    1. jexus防止产生 *.core文件 # vi jws 新增: ulimit -c 0 >/dev/null 2>&1 2.删除*.core # sudo rm -rf *. ...

  4. chrome(谷歌浏览器)老是提示此文件可能损害计算机

    chrome://settings/advanced设置-高级设置-“隐私设置”-取消选中“启用针对网上诱骗和恶意软件的防护功能”复选框试试,

  5. php防注入

    引发 SQL 注入攻击的主要原因,是因为以下两点原因: 1. php 配置文件 php.ini 中的 magic_quotes_gpc选项没有打开,被置为 off 2. 开发者没有对数据类型进行检查和 ...

  6. Excel 使用宏批量修改单元格内指定文字为红字

    -> step 1:新建宏,进入编辑,使用如下代码: Sub Ss()Dim c As RangeFor Each c In ActiveSheet.UsedRange i = 1 While ...

  7. XDU 1161 - 科协的数字游戏II

    Problem 1161 - 科协的数字游戏II Time Limit: 1000MS   Memory Limit: 65536KB   Difficulty: Total Submit: 112  ...

  8. PHPCMS V9多站点[站群功能]动态设置与静态设置子站内容URL

    今天我们来讲解下 PHPCMS V9的站群功能的 动态站点与静态站点的配置 站群站点,分为动态站点,和静态站点两种设置方法: 静态的,就是将栏目和内容都了HTML 文件,我们先讲解下,站群的操作: 建 ...

  9. 解决Button设置disabled后无法执行后台代码问题

    一.开始调式下面的程序,发现Button在js中设置disabled后无法执行后台代码(btnsave_Click)问题 <asp:Button ID="btnsave" r ...

  10. jsp+servlet