selenium禁止弹窗_selenium对付弹出页面

Moving Between Windows and Frames

It's rare for a modern web application not to have any frames or

to be constrained to a single window. WebDriver supports moving

between named windows using the "switchTo" method:

driver.switchTo().window("windowName");

All calls to driver will now be interpreted as being directed to

the particular window. But how do you know the window's name? Take

a look at the javascript or link that opened it:

Click here to open a new window

Alternatively, you can pass a "window handle" to the

"switchTo().window()" method. Knowing this, it's possible to

iterate over every open window like so:

for(Stringhandle:driver.getWindowHandles()){driver.switchTo().window(handle);}

You can also swing from frame to frame (or into iframes):

driver.switchTo().frame("frameName");

It's possible to access subframes by chaining switchTo() calls,

and you can specify the frame by its index too. That is:

driver.switchTo().frame("frameName").switchTo().frame(0).switchTo().frame("child");

would go to the frame named "child" of the first subframe of the

frame called "frameName". All frames are evaluated as if

from currently switched to frame. To get back to the top

level, call:

driver.switchTo().defaultContent();

其实上面还没有搞太懂

不过找到一个解决目前问题的办法:

String windowId = "";

for (String handle : driver.getWindowHandles()) {

if (driver.switchTo().window(handle).getTitle().contains("登录中心")) {

windowId = handle;

break;

}else driver.close();}

driver.switchTo().window(windowId);

login();

这样子得到想要的页面的windowId,然后定位到那个页面上进行操作,对于不需要的页面可以用driver.close()关掉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值