0

I am in a confused state. I am not able to get control of a window which is newly opened. I am using chrome browser for my testing.

Here is the scenario - I am in a facebook window and entered all my details and clicked on Log in. AFter the click event I am getting redirected to a new window. My FB window is closed so I have lost all my control. But for some reason I am not getting control for the newly opened window. Please Help.

  • 1
    to get control of newly open window you should switch to that newly opend window using driver.switchTo().window(); – Sachintha Feb 1 '18 at 3:42
  • Thanks Sachin. But this don't work. I think i have pass a string in this command. driver.switchTo().window("string"); But I dont have control over any window so I cant store any value in the string. I can be very wrong here. but this piece is giving me an error. – Arun Menon Feb 1 '18 at 4:03
2

The below code takes you to the last window which is opened.

Set<String> allwindow = driver.getWindowHandles();
for(String eachwindow:allwindow)

{

driver.switchTo().window(eachwindow);

}

If there are many windows and you want to move to the 2 window, then the below code works:

int i=1;
for(String eachwindow:allwindow)

{

driver.switchTo().window(eachwindow);
System.out.Println(eachwindow);
if(i==2)

{

break;

}

i++;

}
0

I'd try with:

Iterator<String> windowIterator = driver.getWindowHandles();
WebDriver popup = null;
while(windowIterator.hasNext()) { 
    String windowHandle = windowIterator.next(); 
    popup = browser.switchTo().window(windowHandle);
}
0
ReadOnlyCollection<string> windowHandles = InitialiseAppium.driver.WindowHandles;
InitialiseAppium.driver.SwitchTo().Window(windowHandles[1]);

From there windowHandles will get all the windows at the moment. Then just use SwitchTo()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.