Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Set<String> to String

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a simple Selenium project.



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.

Andy
 
Marshal
Posts: 25452
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andy, welcome to the Ranch!

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?
 
Andy Leese
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I hope I've been clear.

Many thanks
 
Paul Clapham
Marshal
Posts: 25452
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic