0

I am facing issue while switching between two windows using selenium web driver.

I am working on automating the web pages using selenium webdriver.

In the parent window I need to click on a button and it will open a new window.I need to fill some data on the new window and click on the save button.After clicking on the save button,this window will be closed automatically and redirected to the parent window and the parent window will be refreshed to dispaly the data that was added on the new window.But during the redirection it is failing to switch back to the parent window and throwing the secutiry violation error.

I am using the below code to switch between windows

 public void switchwindow(){
    try {
    String winHandleBefore = getDriver().getWindowHandle();
    for(String winHandle : getDriver().getWindowHandles()){
        getDriver().switchTo().window(winHandle);

    }

    }catch(Exception e){
    }
 }

Please help me on this issue.

2
  • Try switching back using driver.switchTo().defaultContent(); Commented Apr 4, 2014 at 7:46
  • @aurbano: driver.switchTo().defaultContent(); Curious to know how this code will relate to this question? More over this will be used for frame switch handling. Commented Apr 7, 2014 at 13:35

1 Answer 1

1

I think the correct procedures should be:

  • on parent window, call dirver.getWindowHandle() to save the parentWindowHandle
  • on parent window, click button to open the new window
  • switch to new window, and fill in the data
  • on new window, click save button and close the new window
  • driver.switchTo().window(parentWindowHandle) and then do following stuff...

I'm not sure what the "security violation error" looks like, and it will help if you can post it and other exceptions, thanks!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.