因此,使用 Selenium,我想测试页面上的链接并查看它们是否打开一个新窗口。它们不是 javascript 链接,只是一个基本的 href“target=_blank”。
我想确保新打开的窗口确实加载了页面。
我可以执行所有脚本来单击链接,但是当我测试页面标题时,我得到的是我正在测试的页面,而不是顶部的新窗口。
如何定位该新窗口并检查该页面是否已加载?
thanks
以下内容对我有用,其属性为 target="_blank" 的表单,该表单在新窗口上发送 POST 请求:
// Open the action in a new empty window
selenium.getEval("this.page().findElement(\"//form[@id='myForm']\").target='my_window'");
selenium.getEval("selenium.browserbot.getCurrentWindow().open('', 'my_window')");
//The contents load in the previously opened window
selenium.click("//form[@id='myForm']//input[@value='Submit']");
Thread.sleep(2000);
//Focus in the new window
selenium.selectWindow("my_window");
selenium.windowFocus();
/* .. Do something - i.e.: assertTrue(.........); */
//Close the window and back to the main one
selenium.close();
selenium.selectWindow(null);
selenium.windowFocus();
html 代码类似于:
<form id="myForm" action="/myAction.do" target="_blank">
<input type="text" name="myText" value="some text"/>
<input type="submit" value="Save"/>
</form>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)