Selenium: 处理弹出窗口的workaround

在Selenium中,比较麻烦的是处理弹出窗口,虽然有selectWindow(String windowID)的方法可用,但是对于某些窗口很难拿到windowID的话,比如开发人员没在HTML中提供ID,或者getAllWindowIds()得不到弹出窗口的ID的时候,这个方法基本等于没用。

在这个时候我们可以使用一个workaround:

openWindow(String url, String windowID) :Opens a popup window (if a window with that ID isn't already open). After opening the window, you'll need to select it using the selectWindow command.

比如对于一段HTML代码:<a target="newwindow" href="relative_URL">click here</a>

可以使用xpath得到href的属性:a[text()='click here']@href 

String url = selenium.getAttribute("a[text()='click here']@href "); 

然后再加上server的地址,就得到弹出子窗口的地址 

然后使用OpenWindow(URL, ID)之后

waitForPopUp(ID, delaytime);

selectWindow(ID);

就选中了子窗口,然后可以在上面进行操作,比如验证文字存在,输入数据之类的

转载于:https://www.cnblogs.com/bluescorpio/archive/2010/09/27/1836764.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值