u_untouchable
u_untouchable

Reputation: 129

getWindowHandle function doesn't exist for driver in Selenium

I need to implement switch from one window to another in IE. However, element driver doesn't support getWindowHandle function.

I assume it might be just configuration problem or settings, though I don't know how to fix it.

Please, any suggestions.

I'm working with c# - Visual Studio

Upvotes: 3

Views: 5234

Answers (2)

JimEvans
JimEvans

Reputation: 27486

You haven't said which language bindings you're using, but based on a comment you posted, it looks like you're using C#. The method names are slightly different for each language binding. From this answer:

The object, method, and property names in the .NET language bindings do not exactly correspond to those in the Java bindings. One of the principles of the project is that each language binding should "feel natural" to those comfortable coding in that language.

So you have to do a little translation if you're trying to copy-paste Java code. In this case, you want the combination of the WindowHandles property (to look for the new window handle) and the CurrentWindowHandle property of the driver. You can find full API documentation for the .NET bindings at the project's Google code site.

Upvotes: 4

Pavel Janicek
Pavel Janicek

Reputation: 14738

I am going to make wild guess:

Try to initialize your driver like this:

 WebDriver driver = new FirefoxDriver(); //assume you use firefox

The interface WebDriver supports that method. Do not forget to store the handle somewhere ;)

String myWindow = driver.getWindowHandle();

BTW that method should return you actual window If you need all windows you probably should use getWindowHandles() method

If this does not work, please provide more info:

  • what error exactly are you getting?
  • How do you initialize WebDriver?
  • What version of selenium are you using?|
  • What type of driver are you using?

Upvotes: 1

Related Questions