其他测试框架 selenium 多窗口间无法切换

panzhigang · 2014年07月14日 · 最后由 恒温 回复于 2014年07月14日 · 1352 次阅读

web 测试,页面打开新窗口,但怎样都不能切换到新窗口
代码如下
selenium.selectWindow(selenium.getAllWindowTitles()[1]);

我看了下,下面代码输出都为 1,而我确实开着两个窗口

System.out.println(selenium.getAllWindowTitles().length);
System.out.println(selenium.getAllWindowIds().length);
System.out.println(selenium.getAllWindowNames().length);

求各位大神帮忙解惑

共收到 5 条回复 时间 点赞

不同的窗口 你要拿到 window handler 吧

@lihuazhang 请问下 如果不采用 webdriver 的话该怎样获取 window handler ?

@lihuazhang 谢谢了 我来试下

http://www.seleniumwiki.com/software-testing/selenium-selectwindow/

  • title=My Special Window: Finds the window using the text that appears in the title bar. Be careful; two windows can share the same title. If that happens, this locator will just pick one.
  • name=myWindow: Finds the window using its internal JavaScript “name” property. This is the second parameter “windowName” passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which Selenium intercepts).
  • var=variableName: Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current application window, e.g. “window.foo = window.open(url);”. In those cases, you can open the window using “var=foo”.
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册