利用Selenium Webdriver 2.0 实现通过Web上传文件
来源:互联网 发布:我的世界凋零风暴js 编辑:程序博客网 时间:2024/05/24 02:35
在Web自动化测试实践中,常常会遇到需要通过Web (基本都是依靠form元素) 上传文件到后台的功能。这个功能的特点在于,不仅需要浏览器、document对象的参与,还需要借助于Windows的模式窗口。说到这里,作为我这样的初学者,就会犯难了,怎样才能操作Windows的这个弹出模式窗口呢? Selenium Webdriver有对应的API可以实现我的愿望吗?于是,我会想当然的去遍历Selenium Webdriver的API文档。结果可想而知,高手们要笑了。
如果了解HTML Form表单对象的工作原理,上面的这个问题就很容易有思路。所以做Web自动化测试,不懂web,将会事倍功半。
Form表单里面的文件选择控件<input type="file">,实际也是个可输入的元素,跟<input type="text">元素不同点,从直观上讲,前者没有输入框,后者有。给人的感觉是只有后者才能传递文本或字符,前者不能。so, 只看表面,就掉坑里去了。
要解决本文开始的那个问题,其实跟<input type="text">类似,就是直接把文件地址付给<input type="file">元素,然后submit。
以Selenium Webdriver + python 为例:
Select the <input type="file"> element and call the send_keys() method passing the file path, either the path relative to the test script, or an absolute path. Keep in mind the differences in path names between Windows and Unix systems.
--摘自http://selenium-python.readthedocs.org/faq.html (No. 8.5)
要注意的是,文件路径问题,在windows下,路径一定要这样:c:\\test\\upload\\file,而不能这样写:c:/test/upload/file。
试试看撒!!
如果了解HTML Form表单对象的工作原理,上面的这个问题就很容易有思路。所以做Web自动化测试,不懂web,将会事倍功半。
Form表单里面的文件选择控件<input type="file">,实际也是个可输入的元素,跟<input type="text">元素不同点,从直观上讲,前者没有输入框,后者有。给人的感觉是只有后者才能传递文本或字符,前者不能。so, 只看表面,就掉坑里去了。
要解决本文开始的那个问题,其实跟<input type="text">类似,就是直接把文件地址付给<input type="file">元素,然后submit。
以Selenium Webdriver + python 为例:
Select the <input type="file"> element and call the send_keys() method passing the file path, either the path relative to the test script, or an absolute path. Keep in mind the differences in path names between Windows and Unix systems.
--摘自http://selenium-python.readthedocs.org/faq.html (No. 8.5)
要注意的是,文件路径问题,在windows下,路径一定要这样:c:\\test\\upload\\file,而不能这样写:c:/test/upload/file。
试试看撒!!
0 0
- 利用Selenium Webdriver 2.0 实现通过Web上传文件
- 利用Selenium Webdriver 2.0 实现从Web自动保存文件到本地
- Selenium-Webdriver(python) (十一) --- 文件上传
- selenium实现文件上传
- 利用Selenium实现图片文件上传的两种方式
- 利用Selenium实现文件上传的AutoIt介绍
- Selenium webdriver 使用python脚本处理SWFupload 文件上传
- selenium webdriver学习--利用POI实现数据驱动
- selenium webdriver学习(十二)------------如何利用selenium-webdriver截图
- Selenium 2.0 WebDriver 使用指南
- Selenium 2.0 WebDriver 使用指南
- Selenium 2.0 WebDriver使用指南
- Selenium 2.0 WebDriver 使用指南
- Selenium 2.0 WebDriver 使用指南
- java通过struts实现web中的文件上传
- 利用Selenium实现图片文件上传的两种方式介绍
- java web 利用Struts1实现上传多个文件
- selenium webdriver实现windows 身份验证
- RTSP协议分析-3
- UVA - 818 Cutting Chains 暴力
- Windows下搭建x64 PHP的开发测试环境
- 剑指offer-4 替换空格
- UICollectionView入门--使用系统UICollectionViewFlowLayout布局类
- 利用Selenium Webdriver 2.0 实现通过Web上传文件
- 利用Selenium Webdriver 2.0 实现从Web自动保存文件到本地
- IE下javascript获取文件大小
- ActiveAndroid 源码阅读笔记 (2)
- spring 邮件发送
- 操作系统网关的设置不会影响到11.2 RAC
- (微博实习)tomcat 启动
- centos 上假设svnserve
- MFC Navigate2是做什么的