The childWindowHandle operates fine from inside the While loop. I can close it, switch, etc... But I also want to be able to do this outside the While loop, hence why I added the line String childWindowHandle = null;
Is some conversion required? Is childWindowHandle an array inside the loop and just a String outside?
The error message I get is:
org.openqa.selenium.NoSuchWindowException: Unable to locate window: 2147483657
But System.out.println("Child: " + childWindowHandle); does at least match 2147483657 if not data type.
Please help, as I don't really know what questions to ask.
No, the childWindowHandle variable is declared as String, so it always refers to a String (or to null). It can't refer to an array ever, and anyway I don't see any arrays in your posted code to lead to that idea.
So you want to use it "outside the loop"? You must have some reason to want that, so could you tell us what that reason is? You have a Set of Strings and you're apparently choosing one String from that Set. I don't see any code which chooses so you just get the last one, which may or may not be a good choice. So, what's your requirement here?
posted 1 week ago
Thank you for the welcome.
I'm looking to have a :
variable: parentWindowHandle to be assigned to what I am calling the Parent Window.
variable: childWindowHandle to be assigned to the Child Window (which changes every time the loop is executed).
If everything works fine, that would suffice, but on occasion something is going wrong with the Child Window(s). In that case I would note it down and then would want to close the Child Window manually, refresh the Parent Window and try again (ideally for example of a maximum of three tries). My intention was to program that in a try, catch code. But I don't want to get ahead of myself.
I have initalized the childWindowHandle outside the loop, and outside the loop System.out.println(childWindowHandle); displays the correct 'number' to the console. But webDriver.switchTo().window(childWindowHandle); will not switch to that Window to close it.
My beginner knowledge lead me to believe that because the two childWindowHandles are displayed the same, that the compiler understood them as different (i.e. int a = 12345678 and String a = 12345678). But as you said, this is impossible.
Well, I don't know. The compiler has nothing to do with your problem, of course, because connecting to the web site happens at run time.
So you're going through the set of child windows and picking one -- the last one in the set. And you say that you can use that window handle just fine inside the loop (although I don't see the code which does that). But later, after some code described as "blah blah" you can't use the window handle any more. My guess is that the "blah blah" business does something which makes the window handle invalid.
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Two software engineers solve most of the world's problems in one K&R sized book