1. First Check whether its popup window or IFrame window by using IE Developer or Find bug tools.
2. If its popup window then use following code :
driver.findElement(By.xpath("")).click();
Set s=driver.getWindowHandles();
This method will help to handle of opened windows other than parent
Iterator ite=s.iterator();
while(ite.hasNext())
{
String popupHandle=ite.next().toString();
if(!popupHandle.contains(mwh))
{
driver.switchTo().window(popupHandle);
/**/here you can perform operation in pop-up window**
//After finished your operation in pop-up just select the main window again
driver.switchTo().window(mwh);
}
}
This method will help to filter out of all opened windows
1) String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
if (popup.getTitle().equals("Google") {
break;
}
}
2) Uncomment code for the same popup,
//action in popup "Google".
popup.findElement(By.name("q")).sendKeys("Thoughtworks");
//action in popup "Google".
popup.findElement(By.name("btnG")).submit();"
3) After the popup actions, switch the driver back to the parent window,
browser.close(); // close the popup.
browser.switchTo().window(parentWindowHandle); // Switch back to parent window.
driver.switchTo().Frame(driver.findelement(by.id("iframeid")));
// perform ur actions.
//revert back to parent control
driver.switchTo().window(parentWindowHandle);
No comments:
Post a Comment