Hi guys,
I have a requirement where I have to Select window by Index (Similar to Selenium IDE).
Where: Parent window = win_ser_local
Child window = win_ser_1
Sub-child window = win_ser_2
and so on....
Need help with the below code:
// Keyword : selectWindow, identifier : win_ser_local / won_ser_1
public String selectWindow(int identifier, String data) {
APP_LOGS.debug("Handling selectWindow");
try {
/* Map<String,String> mapWindow = new HashMap<>();
String parent = driver.getWindowHandle();
mapWindow.put("win_ser_local", parent);
int count =1;
for (String s : driver.getWindowHandles()) {
if(s.equals(parent)) continue;
mapWindow.put("win_ser_" + count, s);
count++;
}
System.out.println("windows :: "+mapWindow);
System.out.println("to be select windows :: "+identifier);
driver.switchTo().window(mapWindow.get(identifier)); */
Set < String > s = driver.getWindowHandles();
Iterator < String > ite = s.iterator();
int i = 1;
while (ite.hasNext() && i < 10) {
String popupHandle = ite.next().toString();
driver.switchTo().window(popupHandle);
System.out.println("Window title is : "+driver.getTitle());
if (i == identifier) break;
i++;
}
}
catch (Exception e) {
return Constants.KEYWORD_FAIL + " Could not select window by name. " + e.getMessage();
}
return Constants.KEYWORD_PASS;
}
Test case:
Keyword Target Data
open http://www.seleniumeasy.com/test/
clickAt id=target
clickAt id=target
clickAt id=target (Opens child window)
selectWindow win_ser_1 (Select new window)
type id=target Some text
clickAt id=target (close child window)
close win_ser_1
selectWindow win_ser_local (Select parent window)
clickAt id=target (Opens 2 windows. )
selectWindow win_ser_2 (select sub-child window)
type id=target some text
close win_ser_2 (close sub-child window)
selectWindow win_ser_local (Select parent window)
close win_ser_local (close parent window)
Same for "close" keyword, as shown in the above test case.
Similar functionality required for selectFrames:
where: parent frame = relative:parent
second frame = index = 0
third frame = index=1
and so on...
Any help appreciated. Thanks in advance