watiJ-userGuide部分内容(转载)

本文介绍如何使用特定API进行IE浏览器的自动化操作,包括创建及启动IE实例、网页导航、元素定位与交互等。通过示例展示了如何模拟点击、填写表单、处理下拉列表等常见任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

UserGuide中现有的内容

创建一个IE浏览器实例

 IE ie = new IE();
 
启动一个IE浏览器实例

 IE ie = new IE();
 ie.start();
 
启动一个IE浏览器实例并访问Google

 IE ie = new IE();
 ie.start("http://www.google.com");

使用当前已经打开的IE浏览器

 根据URL指定
 
 IE ie = new  IE();
 ie.attach(url,"http://www.google.com")
 
 根据标题指定
 
 IE ie = new IE();
 ie.attach(title,"Google");
 
IE导航
 ie.goTo("http://www.mysite.com");用IE浏览器访问www.mysite.com
 
 ie.navigate("http://www.mysite.com");功能同上
 
 ie.forward(); 相当于浏览器中的“前进”
 
 ie.back(); 相当与浏览器中的“后退”


窗口焦点、位置、大小以及模式的设置

 ie.bringToFront(); //将窗口置于其他浏览器窗口之前
 ie.focus(); //设定焦点为指定的ie窗口
 
 ie.maximize(); //将窗口最大化,知道占满整个屏幕
  ie.minimize(); //将窗口最小化
 ie.restore(); //将窗口的大小设为上一次的大小。
 
  ie.fullScreen(true); //打开窗口的全屏幕模式
  ie.fullScreen(false); //禁止窗口的全屏幕模式
 
  ie.theatreMode(true); //打开窗口的剧院(Theatre)模式
  ie.theatreMode(false); //禁止窗口的剧院模式
 
  ie.visible(false); //将窗口从桌面上隐藏起来
  ie.visible(true); //恢复窗口可见
 
  ie.left(100); /将窗口到屏幕的左边距设为100
  ie.top(200); //将窗口到屏幕的上边距设为200

得到页面中name="button1"的按钮

  ie.button(name,”button1”);
 
得到页面中name="deleteButton"的所有按钮集合
  ie.buttons(name,”deleteButton”);

得到上面这个集合中的第二个元素,即页面中第二个name="deleteButton"的按钮
 ie.buttons(name,”deleteButton”).get(1); 
// OR
  ie.buttons(name,”deleteButton”).button(1);
 
得到页面中name="deleteButton",value="delete"的所有按钮集合中的第三个按钮
  Button button = ie.buttons(name,”deleteButton”).buttons(value,”Delete”).button(2);
 
得到页面中<MYTAG>的HTML元素
 例如<MYTAG>My Text1</MYTAG>
 ie.htmlElement(tag,”MYTAG”);
 
假如有
 <MYTAG myattr1=”attribute1”>My Text1</MYTAG>
  <MYTAG myattr2=”attribute2”>My Text2</MYTAG>
则可以通过如下方式得到第一个元素
  ie.htmlElement(attribute(“myattr1”,"attribute1"));
  其中htmlElement()中的参数还可以换成以下方式
  tag(String tagName)
  attribute(String name, String value)
  index(int index)
 text(String text)
 name(String value)
 value(String value)
 caption(String value)
 id(String value)
 title(String value)
 alt(String value)
 src(String value)
 action(String value)
 method(String value)
 url(String value)
 href(String value)
 xpath(String expression)
 
超链接
 假如页面中有如下链接
 <a href="googlehttp://google.com">Google</a>
 则可以通过text,url和xpath三种方式得到该链接,并可以使用正则表达式作为参数,click()表示模拟点击该链接
 ie.link(text,"Google").click();
 
 ie.link(text,"/oogl/").click();
 
 ie.link(url,"http://google.com").click();
 
 ie.link(url,"/google.com/").click();
 
 ie.link(xpath, "//A[@url='http://google.com']").click();
 
多选框
 假如页面中有如下多选框
 Check Me: <input name="checkme" value="1" type="checkbox">
 则可以通过如下方式来实现勾选该多选框
 ie.checkbox(name,"checkme").set();
 
 ie.checkbox(value,"1").set();
 
 ie.checkbox(xpath, "//INPUT[@name='checkme' and @value='1']").set();
 还可以调用clear()来取消多选框的选中状态
 
单选框
 假如页面中有如下单选框
 Click Me: <input name="clickme" id="1" type="radio">
 则可以通过如下方式来实现勾选该多选框
 ie.radio(name,"clickme").set();
 
 ie.radio(id,"1").set();
 
 ie.radio(xpath, "//INPUT[@name='clickme' and @id='1']").set();
 还可以调用clear()来取消单选框的选中状态
 
按钮
 假如页面中有如下按钮
 <input type = "submit" value = "ClickTheButton" name="b1"></input>
 可以通过如下方式得到该按钮
 ie.button(name, "b1").click();
 
 ie.button(value,"ClickTheButton").click();
 默认会根据按钮的value值来寻找该按钮,如
 ie.button("ClickTheButton").click();
 
下拉列表
 假如页面中有如下下拉列表
 <select name = "selectme" > <option name="1">O1<option name="2">O2</select>
 可以通过如下方式选中该下拉列表中的选项
 //(finds the option in the select list with name 1)
 ie.selectList(name, "selectme").option(name,"1").select();
 
 //(finds the second option in the list)
 ie.selectList(name, "selectme").option(index,1).select();
 
 //(返回当前下拉列表是否可用,即disable的状态)
 ie.selectList(name, "selectme").disabled();
 
 可以使用clearSelection()方法清除下拉列表的选中状态。
 
图片
 假如页面中有如下图片元素
 <img src = images/square.jpg id=square title="square_image">
 可以通过如下方式实现点击该图片
 ie.image(src, "/square/").click();
 
 ie.image(title, "square_image").hasLoaded();
 
 ie.image(id,"square").width();
 
 ie.image(xpath, "//IMAGE[@id='square']").click();
 
文本框和多行文本区域
 假如页面中有如下文本框
 <input name="username" type="text">
 可以通过如下方式得到文本框的值,或设置其值
 ie.textField(name, "username").set("myusername");
 
 ie.textField(name, "username").value();

得到子浏览器
 当当前浏览器打开一个新的浏览器窗口时,可以使用如下方法得到新的窗口
 IE ie = new IE().start("www.mysite.com");
 //lets click a link that causes a new window to popup
 ie.link(name, "mylink").click();
 //now lets get a handle on the child browser;
 IE new_ie = ie.childBrowser();

 

转载于:https://www.cnblogs.com/keeping/archive/2010/09/23/1833326.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值