1.selectWindow问题。
selectWindow | TestOpenWindow |
如果程序打开了新窗口,那么就要转到新窗口 执行一些操作,这时需要首先选中该新窗口,在selenium中选中新窗口使用selectWindow命令,根据windowID来选择窗口,但是它有一些限制:
a. 只能检测到使用window.open(url, windowName, windowFeatures, replaceFlag)方法打开的窗口。
b. 如果在onLoad事件之前发生的打开窗口,并不能检测到。使用以下命令注册窗口后就能选择。
openWindow | TestOpenWindow |
源代码如下:
<!--File: TestOpenWindowDuringOnLoad.html-->
<
html
>
< head >
< title > Test Local </ title >
</ head >
< body >
< table cellpadding ="1" cellspacing ="1" border ="1" >
< tbody >
< tr >
< td rowspan ="1" colspan ="3" > Test Local < br >
</ td >
</ tr >
< tr >
< td > open </ td >
< td > http://10.202.15.118:8080/myapp/test_open_window_during_onload.jsp </ td >
< td > </ td >
</ tr >
< tr >
< td > openWindow </ td >
< td ></ td >
< td > TestOpenWindowDuringOnLoad </ td >
</ tr >
< tr >
< td > waitForPopUp </ td >
< td > TestOpenWindowDuringOnLoad </ td >
< td > 5000 </ td >
</ tr >
< tr >
< td > selectWindow </ td >
< td > TestOpenWindowDuringOnLoad </ td >
< td > </ td >
</ tr >
< tr >
< td > verifyTitle </ td >
< td > Test HTML </ td >
< td > </ td >
</ tr >
</ tbody >
</ table >
</ body >
</ html >
< head >
< title > Test Local </ title >
</ head >
< body >
< table cellpadding ="1" cellspacing ="1" border ="1" >
< tbody >
< tr >
< td rowspan ="1" colspan ="3" > Test Local < br >
</ td >
</ tr >
< tr >
< td > open </ td >
< td > http://10.202.15.118:8080/myapp/test_open_window_during_onload.jsp </ td >
< td > </ td >
</ tr >
< tr >
< td > openWindow </ td >
< td ></ td >
< td > TestOpenWindowDuringOnLoad </ td >
</ tr >
< tr >
< td > waitForPopUp </ td >
< td > TestOpenWindowDuringOnLoad </ td >
< td > 5000 </ td >
</ tr >
< tr >
< td > selectWindow </ td >
< td > TestOpenWindowDuringOnLoad </ td >
< td > </ td >
</ tr >
< tr >
< td > verifyTitle </ td >
< td > Test HTML </ td >
< td > </ td >
</ tr >
</ tbody >
</ table >
</ body >
</ 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-->
<
html
>
< head >
< title > Test Local </ title >
</ head >
< body >
< table cellpadding ="1" cellspacing ="1" border ="1" >
< tbody >
< tr >
< td rowspan ="1" colspan ="3" > Test Local < br >
</ td >
</ tr >
< tr >
< td > open </ td >
< td > http://10.202.15.118:8080/myapp/test_open_window_without_id.jsp </ td >
< td > </ td >
</ tr >
< tr >
< td > click </ td >
< td > testopenwindow </ td >
< td > </ td >
</ tr >
< tr >
< td > waitForPopUp </ td >
< td > undefined </ td >
< td > 5000 </ td >
</ tr >
< tr >
< td > selectWindow </ td >
< td > undefined </ td >
< td > </ td >
</ tr >
< tr >
< td > verifyTitle </ td >
< td > Test HTML </ td >
< td > </ td >
</ tr >
</ tbody >
</ table >
</ body >
</ html >
< head >
< title > Test Local </ title >
</ head >
< body >
< table cellpadding ="1" cellspacing ="1" border ="1" >
< tbody >
< tr >
< td rowspan ="1" colspan ="3" > Test Local < br >
</ td >
</ tr >
< tr >
< td > open </ td >
< td > http://10.202.15.118:8080/myapp/test_open_window_without_id.jsp </ td >
< td > </ td >
</ tr >
< tr >
< td > click </ td >
< td > testopenwindow </ td >
< td > </ td >
</ tr >
< tr >
< td > waitForPopUp </ td >
< td > undefined </ td >
< td > 5000 </ td >
</ tr >
< tr >
< td > selectWindow </ td >
< td > undefined </ td >
< td > </ td >
</ tr >
< tr >
< td > verifyTitle </ td >
< td > Test HTML </ td >
< td > </ td >
</ tr >
</ tbody >
</ table >
</ body >
</ 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" οnclick='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" οnclick='javascript:myLoad()'>TestOpenWindowWithoutID</button>
</center>
</body>
</html>
<script language=javascript>
function myLoad(){
window.open("test.html");
}
</script>