WebSpec自动访问页面的使用
来源:互联网 发布:嵌入式linux开发pdf 编辑:程序博客网 时间:2024/05/07 18:56
WebSpec是Watij自动化测试项目里面的一个类。Watij工具调用ie、firefox等浏览器对网页进行测试,也就是说可以解析javascript,对于那些需要手工操作的填表单等工作都可以用Watij模拟。
下面以自动点击baidu,并填入“黄河”为搜索关键词进行搜索作为例子。
先用Dreamweaver查看baidu首页的源代码。
- <div id="m"><p id="lg"><img src="http://www.baidu.com/img/baidu_sylogo1.gif" width="270" height="129" usemap="#mp"><map name="mp"><area shape="rect" coords="40,25,230,95" href="http://hi.baidu.com/baidu/" target="_blank" title="点此进入 百度的空间" ></map></p><p id="nv"><a href="http://news.baidu.com">新 闻</a> <b>网 页</b> <a href="http://tieba.baidu.com">贴 吧</a> <a href="http://zhidao.baidu.com">知 道</a> <a href="http://mp3.baidu.com">MP3</a> <a href="http://image.baidu.com">图 片</a> <a href="http://video.baidu.com">视 频</a> <a href="http://map.baidu.com">地 图</a></p><div id="fm"><form name="f" action="/s"><span class="s_ipt_wr"><input type="text" name="wd" id="kw" maxlength="100" class="s_ipt"></span><input type="hidden" name="rsv_bp" value="0"><input type="hidden" name="rsv_spt" value="3"><span class="s_btn_wr"><input type="submit" value="百度一下" id="su" class="s_btn" onMouseDown="this.className='s_btn s_btn_h'" onMouseOut="this.className='s_btn'"></span></form><span class="tools"><span id="mHolder"><div id="mCon"><span>输入法</span></div></span></span><ul id="mMenu"><li><a href="#" name="ime_hw">手写</a></li><li><a href="#" name="ime_py">拼音</a></li><li class="ln"></li><li><a href="#" name="ime_cl">关闭</a></li></ul></div>
输入框对应的源代码:<input type="text" name="wd" id="kw" maxlength="100" class="s_ipt">
“百度一下”按钮对应的源代码:<input type="submit" value="百度一下" id="su" class="s_btn" onMouseDown="this.className='s_btn s_btn_h'" onMouseOut="this.className='s_btn'">
用WebSpec打开baidu的url,并填入“黄河”,点击搜索:
- public void run(){
- WebSpec spec = new WebSpec().ie();
- if(spec.ready())
- {
- spec.open(url);
- spec.pauseUntilReady();
- spec.find.input().with.name("wd").set.value("黄河");
- spec.find.input().with.id("su").click();
- System.out.println(spec.source());
- }
- else{
- System.out.println("not ready");
- }
- spec.close();
- }
下载:
http://sourceforge.net/projects/watij/files/
API:
http://watij.com/webspec-api/
好酷的自动化测试框架,超酷的自动化请求爬虫框架!
从watij升级后,发现,这个已经远远地超过了httpclient,大大提高了开发效率!
http://blog.csdn.net/waleking/article/details/7271003
http://blog.sina.com.cn/s/blog_66ed71e1010132j1.html
0 0
- WebSpec自动访问页面的使用
- WebSpec自动访问页面的使用
- WebSpec自动访问页面的使用
- 访问页面表单自动提交
- 访问某页面后自动执行某一action的方法
- 使用规范的方法访问页面元素
- 使用NodeVisitor访问HTML页面的TAG
- 使用到iframe的页面中父页面和子页面之间的访问
- [Python]使用Selenium的webdriver访问页面(Firefox的geckodriver)
- 访问页面的计数器
- 访问页面的流程
- 使用Tomcat访问JSP页面时遇到的问题
- 使用Intent跳转后清除以前所访问的页面
- 使用javabean实现当前页面的访问次数(jsp)
- jsp页面使用网络路径访问图片的乱码问题解决
- 使用Intent跳转后清除以前所访问的页面
- 使用weblogicg访问JSP页面都报NullPointerException的问题
- 浏览器访问网页的时候会自动使用co…
- Laravel整合UEditor编辑器使用阿里云OSS存储(一)UEditor搭建和使用
- 猜数字
- Watij——Java开源Web测试工具
- Leetcode 118. Pascal's Triangle
- 自定义ViewpagerIndicator (仿猫眼,添加边缘回弹滚动效果)
- WebSpec自动访问页面的使用
- Zookeeper 的学习与运用
- 官网 Centos 6.5 Setting up Icinga 2 -- Setting up Icinga Web 2
- 第四周项目(5)-递归返回第n个Fibnacci数
- 两个input之间有空隙,处理方法
- Axure RP
- Tomcat访问日志详细配置
- 基于 Jenkins 快速搭建持续集成环境
- 大O记法