IEDriverServer hangs when getting cookies on newly opened window
Meta -
OS:
Windows 10 (64-bit) and Windows Server 2012 R2 (64-bit)
Selenium Version:
3.4.0
Browser:
Internet Explorer
Browser Version:
- Windows 10: 11.413.15063.0 ~~(both 32-bit and 64-bit)~~
- Windows Server 2012 R2: 11.0.9600.18538 ~~(both 32-bit and 64-bit)~~
Expected Behavior -
don't hang up when getting cookies on newly opened window.
Actual Behavior -
hang up when getting cookies on newly opened window.
Steps to reproduce -
- Create WebDriver instance.
- open first window by e.g. driver.get()
- open another window by e.g. executing JavaScript "window.open()".
- switch to newly opened windw.
- try to get cookies.
following Java and python code my reproduce this issue. (python version needs remote IE webdriver stup)
Java:
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class GetCookiesOnAnotherWindow {
public static void main (String[] args) {
WebDriver driver = new InternetExplorerDriver();
try {
driver.get("about:blank");
((JavascriptExecutor) driver).executeScript("window.open('about:blank', 'another_window')");
driver.switchTo().window("another_window");
driver.manage().getCookies(); // <- IE Driver hangs here
} finally {
driver.quit();
}
}
}
Python:
# coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
try:
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
driver = webdriver.Remote(desired_capabilities=caps)
driver.get("about:blank")
driver.execute_script("window.open('about:blank','another_window')")
driver.switch_to.window('another_window')
cookies = driver.get_cookies() # Hang up HERE.
except Exception:
pass
finally:
driver.quit()
What version of the IE driver are you using? 32-bit or 64-bit?
@koichirok
your examples are trying to get cookies from about:blank, which isn't going to work. For example, navigate to about:blank, open a js console and execute document.cookie. You will get an error.
You should change your Python example so it doesn't swallow all exceptions. If you removed that try/except, you would actually see a stacktrace of the error being thrown. If you post the error here, it will be a lot more helpful than generically saying it "hangs up"
@koichirok @cgoldberg I have been having similar issues. My problem arises when I simply try to open a window. The window I am opening is about:blank and I'm opening it by clicking a link, not getting it like koichirok has done. However, I noticed that if I have a second window is open before the test is run, it will work fine. I don't know if this is a fix, but it let's me run through the test.
I am using the 32-bit version of the driver.
I am using Java and catching and printing my stack trace. Nothing is ever thrown. I get the IE Error and when I close the error window, nothing happens. It will actually leave the method I have to handle my popups and continue, but not execute anything from what I can tell. I should be getting NoSuchElementExceptions from my other queries, but nothing is ever thrown. It permanently hangs.
If they are describing the same error I am experiencing, I don't know if changing their try/catch would result in a stack trace. I also don't think that it is the retrieval of the cookie that is causing the issue, I believe it is simply opening the window.
@jimevans I've tested both 32bit and 64bit.
IE 11.1358.1439.0 launches and then hangs (NoSuchWindow) - after the GoToUrl command, the WindowHandlers are suddenly zero. Works fine for older build of IE11.
On StackOverflow I have read:
Microsoft has changed the behavior of IE11, and broken the IE driver in the process. The problem is with the browser's behavior change. There is no clear-cut workaround yet.
@cgoldberg My examples are minimum code to reproduce this issue, when I use normal URL like www.google.com, and open new window by non JavaScript way (e.g. sending Ctrl+Return), issue also occurred.
And as @TheShed412 mentioned above, exception is never thrown.
When I run IEDriverServer with --log-level=debug, IEDriverServer seems to hang up when trying to process "get all cookies".
@Exoow @koichirok
A work around I have found is opening another window before running the test that produces the pop up. I haven't implemented it but I was going to try making another instance of the driver and just opening another window at the beginning of the test. I have just been opening one manually before running the test and it opens and switches to the pop up with out error.
Also, it seems to get hung-up in the switchTo method. It seems that it generates the error when I am getting the handles and it hangs when trying to switch to it. So I was incorrect in my last comment thinking that the rest of my tests tried executing. They don't because the program hangs inside of the switchTo method.
It sounds like we have two different issues here, and it's getting confusing between the two. A trace-level log would be instructive in both cases. Neither case is globally broken for every instance of opening a new window. @TheShed412 can you provide a reproduction case with a log from IEDriverServer? @koichirok can you please provide a trace-level log?
@jimevans I will open a new issue if these are two different problems.
@jimevans I've uploaded IEDriver's trace log of another test code (below) to my gist.
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class GetCookiesOnAnotherWindow {
public static void main (String[] args) {
WebDriver driver = new InternetExplorerDriver();
try {
driver.get("www.seleniumhq.org");
String initialWh = driver.getWindowHandle();
WebElement e = driver.findElement(By.linkText("Download"));
e.sendKeys(Keys.chord(Keys.CONTROL,Keys.RETURN));
for (String wh : driver.getWindowHandles()) {
if (wh.equals(initialWh))
continue;
driver.switchTo().window(wh);
System.out.println("Current Window Handle: " + driver.getWindowHandle());
System.out.println("Current URL: " + driver.getCurrentUrl());
System.out.println("Current Title: " + driver.getTitle());
System.out.println("Cookies:" + driver.manage().getCookies());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}
}
output of the above code is below. "Cookies:" line is not written and no exceptions are thrown after more than 20 minutes passed since I ran the program.
Started InternetExplorerDriver server (32-bit)
3.4.0.0
Listening on port 36390
Log level is set to TRACE
Log file is set to C:\Users\koichiro\Selenium\iedriver.log
Only local connections are allowed
7 13, 2017 4:04:32 午後 org.openqa.selenium.remote.ProtocolHandshake createSession
情報: Detected dialect: OSS
Current Window Handle: 8355a7c2-d725-45cd-a0d1-9e0a224155bd
Current URL: http://www.seleniumhq.org/download/
Current Title: Downloads
@koichirok Your gist tells me exactly what I expected was the issue. There's something going on with the Windows hook procedure that we use to get the cookies from within the browser. I'll need to investigate what it underlying cause is. I do want to set your expectations on a time frame, however. It will be several days, maybe even a few weeks until my schedule frees up enough for me to give the matter the attention it needs. Asking for updates via comments in this issue will not be conducive to hastening that process. Thank you for the issue report.
@koichirok, it's totally tangential at this point, but I wanted to respond to your comments directed towards me
My examples are minimum code to reproduce this issue,
What you need to provide is a minimal working example. Your contrived code when run as-is causes a different error for a different reason. All that does is make more work for someone trying to reproduce.
when I use normal URL like www.google.com, and open new window by non JavaScript way (e.g. sending Ctrl+Return), issue also occurred.
If those conditions reproduce the issue, then why didn't you just supply an example using them?
And as TheShed412 mentioned above, exception is never thrown.
My point was that the way your code is structured, it will never display a stacktrace, so you wouldn't know whether an exception was thrown. Using your original example python code, there is no way to differentiate between "no exception was thrown" and "and exception was thrown, but my exception handler swallowed it". Those are 2 very different things.
I made my original comments because a maintainer's time is valuable and shouldn't be spent chasing down errors by running contrived and incorrect examples. The better the reproduction steps and examples you can provide, the more likely it will be fixed. Basically, "help me help you".
... kind of like Jerry Maguire pleaded to Rod Tidwell (click to watch):

@jimevans I've reboot my windows 10 BOX and now 64bit version of IEDriverServer works fine, report following Exception as expectedly:
org.openqa.selenium.WebDriverException: Could not retrieve cookies. The most common cause of this error is a mismatch in the bitness between the driver and browser. In particular, be sure you are not attempting to use a 64-bit IEDriverServer.exe against IE 10 or 11, even on 64-bit Windows. (WARNING: The server did not provide any stacktrace information)
32bit version of IEDriverServer still hangs, so it's a 32bit version of IEDriverServer's issue.
32bit version of IEDriverServer still hangs, so it's a 32bit version of IEDriverServer's issue.
I've also rebooted my Windows Server 2012 R2 box (on AWS), but both 32bit and 64bit version of IEDriverServer.exe still hangs on it.
any solution? I am getting the same issue
I still see this. Is this known and open ?
Exception org.openqa.selenium.WebDriverException: Could not retrieve cookies. The most common cause of this error is a mismatch in the bitness between the driver and browser. In particular, be sure you are not attempting to use a 64-bit IEDriverServer.exe against IE 10 or 11, even on 64-bit Windows
For what it's worth, I've fixed this issue in 318257c. It will be released widely in 3.15. Please note there is no time table for this release. People encountering this particular issue are welcome to use the pre-built 3.14.0.5 driver checked into the source tree.