简体   繁体   中英

Unable to switch back to the parent window from the popup frame using selenium webdriver

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....

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

Try using this code:-

driver.switchTo().frame("Frame_identifier");

//your code

String winHandleBefore = driver.getWindowHandle(); webDriver.SwitchTo().Window(winHandleBefore);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM