导航

 

在selenium中虽然有selectWindow(String windowID) 方法,但是对于一些窗口很难取得其window ID的话,如果开发人员没有在html代码中提供ID ,或者getAllWindowIds()得不到弹出窗口的ID的时候,那么这个方法基本等于没用。

那么我们可以这样处理:
先使用 openWindow(String url,String WindowID)来打开一个弹出窗口,然后我们在选择他。
如对于一段html代码:
<a target="newwindow" href="http://blog.163.com/yang_jianli/blog/url_address">注册</a>

可以使用xpath得到href属性:
a[text()='click here']@href
获得弹出窗口的url:
String url= selenium.getAttribute(”a[text()='注册']@href“);

然后再加上server的地址,就得到弹出子窗口的地址,然后使用OpenWindow(url,idname)来打开ID为idname的弹出窗口;
等待弹出:
waitForPopup(id,delaytime)
选择弹出的窗口:
selectWindow(id)

以上为java函数的代码,下面是python格式代码:


 url = sel.get_attribute("//a[text()=u'注册']@href")
 url2=url_base + url         #url_base为server地址
 sel.open_window(url2, 'testid')
 wait_for_pop_up(‘testid’,5)
 sel.select_window("testid")
 
转载自:http://blog.163.com/yang_jianli/blog/static/161990006201242932840371/
posted on 2015-05-21 17:10  slqt  阅读(432)  评论(0编辑  收藏  举报