Reputation: 21
I have the login page, when click login its opens the new tab. I moved the control to new tab using
driver.switchTo().window("");
// Done some stuffs in new window.
when I click one Button it will open the popup (frame).
I have selected a popup window using driver.switchTo().frame("frameName");
and from there by selecting the record, the popup window will be closed. The selected record will be displayed in parent window and the page got refreshed.
Now I want to return(Re-Focus) the control to my parent window for doing the some other stuffs.
but I could not focus the parent window again.
I have tried:
driver.switchTo().defaultcontent();
driver.switchTo().window("");
and
driver.getWindowHandles();
Still the same result....
Could anyone please help me on this....
Upvotes: 1
Views: 5975
Reputation: 169
Try using this code:-
driver.switchTo().frame("Frame_identifier");
//your code
String winHandleBefore = driver.getWindowHandle(); webDriver.SwitchTo().Window(winHandleBefore);
Upvotes: 1
Reputation: 21
String oldWindow = driver.getWindowHandle();
driver.findElement(By.xpath("//a[@id='searchSalesImg']/img")).click();
//by clicking on this we will get a new window
Thread.sleep(5000);
driver.switchTo().window(driver.getWindowHandle());
driver.switchTo().window("Employer Services Order Management (ESOM)");
//Navigate to new window
driver.findElement(By.id(" Primary Sales Person:")).sendKeys("MAS%");
//Do some stuff in new window
driver.switchTo().window(oldWindow);
//navigate back to old window
Upvotes: 2