1.selectWindow问题。
selectWindow | TestOpenWindow |
如果程序打开了新窗口,那么就要转到新窗口 执行一些操作,这时需要首先选中该新窗口,在selenium中选中新窗口使用selectWindow命令,根据windowID来选择窗口,但是它有一些限制:
a. 只能检测到使用window.open(url, windowName, windowFeatures, replaceFlag)方法打开的窗口。
b. 如果在onLoad事件之前发生的打开窗口,并不能检测到。使用以下命令注册窗口后就能选择。
openWindow | TestOpenWindow |
源代码如下:
<!--File: TestOpenWindowDuringOnLoad.html-->










































<!--File: test_open_window_during_onload.jsp-->
<html>
<head>
<title>Test Open Window</title>
</head>
<body>
<center>
<text id=text1>Hello, Open a new Window During OnLoad!</text>
</center>
</body>
</html>
<script language=javascript>
myLoad();
function myLoad(){
window.open("test.html","TestOpenWindowDuringOnLoad");
}
</script>
<head>
<title>Test Open Window</title>
</head>
<body>
<center>
<text id=text1>Hello, Open a new Window During OnLoad!</text>
</center>
</body>
</html>
<script language=javascript>
myLoad();
function myLoad(){
window.open("test.html","TestOpenWindowDuringOnLoad");
}
</script>
c.如果使用window.open(url),未指定窗口ID,那么使用undefined标志窗口ID来选择窗口。
selectWindow | undefined |
源代码如下:
<!--File: TestOpenWindowWithoutID.html-->










































<!--File: test_open_window_without_id.jsp-->
<html>
<head>
<title>Test Open Window</title>
</head>
<body>
<center>
<text id=text1>Hello, Open a new Window Without ID!</text>
<button id="testopenwindow" onclick='javascript:myLoad()'>TestOpenWindowWithoutID</button>
</center>
</body>
</html>
<script language=javascript>
function myLoad(){
window.open("test.html");
}
</script>
<head>
<title>Test Open Window</title>
</head>
<body>
<center>
<text id=text1>Hello, Open a new Window Without ID!</text>
<button id="testopenwindow" onclick='javascript:myLoad()'>TestOpenWindowWithoutID</button>
</center>
</body>
</html>
<script language=javascript>
function myLoad(){
window.open("test.html");
}
</script>