org.openqa.selenium.NoSuchWindowException: No window found using IE 8 and webdriver 2.0

2,508 views
Skip to first unread message

JK

unread,
Jun 20, 2013, 2:54:18 AM6/20/13
to webd...@googlegroups.com, Jaikrishna Shukla
Hi ,

I am getting the following error when using IE 8 and webdriver 2.The same peice of code works fine when used with chrome driver.I am not too sure whats wrong.I also tried adding a sleep before driver.switchTo,window()

the snippet of my code is  :

driver.findElement(By.id("loginbuttons")).click();
   Thread.sleep(5000);
driver.findElement(By.linkText(Apllication)).click();
 
   driver.findElement(By.id("button_logon")).click();


   
   driver.switchTo().window(Window);   

   assertEquals(IBlogonURL, driver.getCurrentUrl());

And the Error is :

org.openqa.selenium.NoSuchWindowException: No window found (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.45 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_11'
Session ID: 93aa8233-0f43-4bf2-aa43-45484dec5b97
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=8, cssSelectorsEnabled=true, ignoreProtectedModeSettings=true, requireWindowFocus=false, initialBrowserUrl=, handlesAlerts=true, nativeEvents=true, browserAttachTimeout=0, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:831)
at com.seleniumtests.test.IBLogon.launchWCM(IBLogon.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access$0(SuiteRunner.java:333)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

darrell

unread,
Jun 20, 2013, 10:02:59 PM6/20/13
to webd...@googlegroups.com, Jaikrishna Shukla
If it works in Chrome but not in IE it is probably a timing issue. IE is know to be slower than other browsers. Which line opens the new window? if the first click opens the new window then it makes sense to "click, wait 5 seconds, do some thing stuff, switch to the new window". However, if the third click is opening the window, the time between the click and switching to the window has not changed. I would put the 5 second sleep before the driver.switchTo().window(Window) call. If that works then you know you need to wait for the window to appear.

I wrote a blog entry about switching to a popup window. You can find it at http://darrellgrainger.blogspot.com/2012/04/how-to-find-popup-window-if-it-does-not.html.

Essentially, what it does is take the web element for the element which pops open a window. It then:

    get a list of all existing window handles
    click the element based on the provided web element
    get a list of all existing window handles
    subtract all the handles from the first list from the second list
    switch to the new window by handle

This should result in the second list having only one element, the new popup window. In your case the second list will be the same as the first list and fail. You would then do one extra step:

    one = list of all existing window handles
    click the element based on the provided web element
    do {
        two = list of all existing window handles
        sleep for 50ms
    while(one.size() == two.size());
    subtract all the handles from the first list from the second list
    switch to the new window by handle

The loop is the trick. It will sleep for 50ms, check to see if we found the new window, sleep 50ms, check to see if we found the new window.

On Chrome, it will find the window on the first pass, no looping. On IE it will loop just long enough to find the new window (might be 100ms or it might be 5s; doesn't matter).
Reply all
Reply to author
Forward
0 new messages