Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

IE driver - Does not set cookie #1227

Closed
lukeis opened this issue Mar 2, 2016 · 52 comments
Closed

IE driver - Does not set cookie #1227

lukeis opened this issue Mar 2, 2016 · 52 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1227

What steps will reproduce the problem?
1.  driver.manage().addCookie(testCookie); does not work in IE driver.  


What is the expected output? What do you see instead?
The cookie should be set in the IE. But It does not.

What version of the product are you using? On what operating system?
selenium-server-standalone-2.0b1.jar
Windows XP, IE-7

Please provide any additional information below.

It works like a charm for firefox and chrome. Attached sample code for the test.

Run the test "java CookieTest ie" . 

Reported by Densildesilva on 2011-01-24 10:15:47


- _Attachment: [CookieTest.java](https://storage.googleapis.com/google-code-attachments/selenium/issue-1227/comment-0/CookieTest.java)_
@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by antlong on 2011-01-25 01:08:02

  • Labels added: Browser-IE

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

The IE Driver has been rewritten, can you please retest this?

Reported by theautomatedtester on 2011-04-12 06:18:32

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This still appears to be an issue (r12089).

Reported by derekslager on 2011-04-29 17:08:39

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by jari.bakken on 2011-04-30 16:06:55

  • Status changed: New
  • Labels added: Component-WebDriver

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I m migrating my Selenium1.0 tests with Selenium 2.0. Tests are working fine with 1.0
JAR. But when i use Selenium 2.0, actually setCookie() method is not working and because
of that my tests are failing. Please let me know what to do for this.

Reported by sunil.kmrv on 2011-07-21 04:58:08

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

FYI -- I'm able to set cookies on Selenium v2.5.0 by disabling all Protected modes (and
using the standard IE browser security defaults).

http://hustoknow.blogspot.com/2011/08/trouble-with-protected-mode-in-selenium.html

Reported by roger.hu on 2011-08-31 20:47:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hello Roger, 
you are just able to set cookies for IE runnig on Vista or higher. 
IE 7 or 8 running on XP does not have the "Protected mode" option just standard IE
browser security zones. And this is definitively not working.

Can you please look at that guys? Thank you. 

Reported by jackatkoeln on 2011-11-22 15:36:45

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I've run into the same problem with some, but not all cookies that I set in IE7/8. 
Tested using Sauce Labs, IE7/8 and Windows XP.  The same code works as expected in
IE9, Chrome, and Firefox 7.

Reported by yurodivuie on 2011-12-03 00:51:26

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Definitely not able to add cookies in IE7/8 on windows XP, can set cookies in IE9/Chrome/firefox
.

Reported by shiva.hemanth on 2012-01-09 05:37:47

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

We have tests which show that this works in some cases. Please supply a *full* reproduction
test script.

Reported by dawagner on 2012-02-05 17:51:44

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This is still an issue (at least in IE8, Selenium 2.18 on Windows 7 using C#)
Interestingly the problem reproduces for me after firing an event on an aspx page (clicking
a button) if WebDriver is using only a single window. If I user Javascript to open
a second window in the session, do my test work their but set cookies in the other
window the test passes.
I have not had time to investigate any further and appreciate any suggestions.

Reported by jemau@daptiv.com on 2012-02-22 17:27:58

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Running the following never gets "found my cookie!" running selenium-server-standalone-2.15.0.jar,
in IE8 on Win7.  Runs fine in Firefox.

------------
Cookie cookie = new Cookie("foo", "bar");
driver.manage().addCookie(cookie);

Set<Cookie> allCookies = driver.manage().getCookies();
for (Cookie aCookie : allCookies)
{
    if (aCookie.getName().equals("foo"))
        println("found my cookie!");
}

Reported by brindiebrindinsky on 2012-03-09 23:02:33

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I can confirm the same, also it appears that cookie handling in general might be faulty

Reported by dgtlmoon on 2012-05-08 01:05:27

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

OK, if i run my standalone server with "-singleWindow" option, i get all sorts of cookie
wierdness, without this, it works for me, does that help your problem?

Reported by dgtlmoon on 2012-05-08 01:17:12

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

We start the standalone server by running simply "java -jar selenium-server-standalone-2.15.0.jar".
 No arguments.

Reported by brindiebrindinsky on 2012-05-08 15:54:08

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Another work around is to just set cookies via javascript until addCookie is fixed.

Example: driver.ExecuteScript(string.Format("document.cookie='{0}={1}; expires={2};
path={3}; domain={4}'", ... args);

Reported by jemau@daptiv.com on 2012-05-08 18:33:54

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This worked as recently as 2.23.1, but seems to be broken again in 2.24.1?

stacktrace and small java to try to add cookie: https://gist.github.com/3042607 
saucelabs recording of cookie failure: https://saucelabs.com/jobs/431ce1dfc2cc4096892fdc68e4d8a5ef

Reported by gempesaw on 2012-07-03 20:19:04

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Still present in 2.28.0. 
Windows 7, IE 8.0.7601.17514

Reported by aleksander.wirth on 2013-01-25 13:37:20

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

It also does not work on 2.32.0.0, and getCookies(); returns 0 elements, but cookies
exists 100% in IE!

Reported by sergey.boguckiy on 2013-04-12 08:58:13

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

it works on 2.33, with IE 10.0.9200.16580, Windows 8 x64.
the result of the test case is:

Cookie :- [test=1369400969596; path=/]

Reported by glacier.geng on 2013-05-24 13:35:28

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Note that cookies with the HttpOnly field set cannot be retrieved through the IE webdriver
interface (since these cookies are hidden from javascript). This may describe some
of the errors encountered.

Reported by gazimon on 2013-08-06 03:27:45

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

setCookie is broken for at least IE 6,7,8,9 in Selenium v 2.33
work fine on FF and Chrome

org.openqa.selenium.WebDriverException: Unable to add cookie to page (WARNING: The
server did not provide any stacktrace information) 

Reported by ricardo.j.lopez on 2013-08-21 17:24:03

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi!

Is this issue still actual?

If so please provide the following:
1. executable test script
2. public URL or HTML+CSS+JS of page at which the problem is reproduced
3. IE settings: protected mode state, confidentiality settings

It would be good if you provide IE driver TRACE log.

Reported by a.u.savchuk on 2013-09-20 13:03:37

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

It's still actual:IE8 + Win7X64,by the way ,when it will be fixed? thx.

Reported by skyofdl on 2013-11-26 09:48:02

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

We encountered the same issue and found this page that had a possible solution:

http://kenhirakawa.com/selenium-unable-to-add-cookie-to-page/

It worked for us. Could be worth looking into.

Reported by mikael.larsson@romram.nu on 2013-11-27 10:03:02

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Kinda related to this issue as well:

https://code.google.com/p/selenium/issues/detail?id=4307

Reported by mikael.larsson@romram.nu on 2013-11-27 10:07:03

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Would love to see an IEDriverServer log file from a version of IEDriverServer.exe with
a version later than 2.37.0.1 where the problem is still occurring.

Reported by james.h.evans.jr on 2014-01-29 23:27:34

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Jim, here is the log from IEDriver version 2.39. Selenium server version is 2.39 as
well. Test was to read all cookies, delete the JSessionID cookie and add it back with
a new value. 

D 2014-02-13 12:19:54:555 server.cc(239) Command: POST /session/912c7d96-669e-47d6-b10d-66aae627f1ff/cookie
{"cookie":{"name":"JSESSIONID","secure":false,"value":":1755905sm","path":"/","class":"org.openqa.selenium.Cookie","hCode":1737295111}}
T 2014-02-13 12:19:54:555 server.cc(346) Entering Server::LookupSession
T 2014-02-13 12:19:54:555 IESession.cpp(187) Entering IESession::ExecuteCommand
T 2014-02-13 12:19:54:555 IECommandExecutor.cpp(151) Entering IECommandExecutor::OnSetCommand
T 2014-02-13 12:19:54:555 command.cc(27) Entering Command::Populate
D 2014-02-13 12:19:54:555 command.cc(33) Raw JSON command: { "command" : "addCookie",
"locator" : { "sessionid" : "912c7d96-669e-47d6-b10d-66aae627f1ff" }, "parameters"
: {"cookie":{"name":"JSESSIONID","secure":false,"value":":1755905sm","path":"/","class":"org.openqa.selenium.Cookie","hCode":1737295111}}
}
T 2014-02-13 12:19:54:555 IECommandExecutor.cpp(162) Entering IECommandExecutor::OnExecCommand
T 2014-02-13 12:19:54:555 IECommandExecutor.cpp(453) Entering IECommandExecutor::DispatchCommand
T 2014-02-13 12:19:54:555 IECommandExecutor.cpp(569) Entering IECommandExecutor::GetCurrentBrowser
T 2014-02-13 12:19:54:556 IECommandExecutor.cpp(575) Entering IECommandExecutor::GetManagedBrowser
T 2014-02-13 12:19:54:556 IECommandExecutor.cpp(525) Entering IECommandExecutor::IsAlertActive
T 2014-02-13 12:19:54:556 Browser.cpp(631) Entering Browser::GetActiveDialogWindowHandle
T 2014-02-13 12:19:54:556 Browser.cpp(175) Entering Browser::GetWindowHandle
D 2014-02-13 12:19:54:556 IECommandExecutor.cpp(539) No alert handle is found
T 2014-02-13 12:19:54:556 IECommandExecutor.cpp(569) Entering IECommandExecutor::GetCurrentBrowser
T 2014-02-13 12:19:54:556 IECommandExecutor.cpp(575) Entering IECommandExecutor::GetManagedBrowser
T 2014-02-13 12:19:54:556 DocumentHost.cpp(235) Entering DocumentHost::AddCookie
T 2014-02-13 12:19:54:556 Browser.cpp(95) Entering Browser::GetDocument
I 2014-02-13 12:19:54:556 Browser.cpp(99) No child frame focus. Focus is on top-level
frame
T 2014-02-13 12:19:54:556 IESession.cpp(208) Beginning wait for response length to
be not zero
T 2014-02-13 12:19:54:561 Browser.cpp(557) Entering Browser::GetDocumentFromWindow
T 2014-02-13 12:19:54:564 DocumentHost.cpp(292) Entering DocumentHost::IsHtmlPage
W 2014-02-13 12:19:54:564 DocumentHost.cpp(296) Unable to get mime type for document,
call to IHTMLDocument2::get_mimeType failed
W 2014-02-13 12:19:54:564 DocumentHost.cpp(248) Unable to add cookie, document does
not appear to be an HTML page
T 2014-02-13 12:19:54:564 response.cc(68) Entering Response::SetErrorResponse
W 2014-02-13 12:19:54:564 response.cc(69) Error response has status code 16 and message
'Unable to add cookie to page' message
T 2014-02-13 12:19:54:564 IECommandExecutor.cpp(569) Entering IECommandExecutor::GetCurrentBrowser
T 2014-02-13 12:19:54:564 IECommandExecutor.cpp(575) Entering IECommandExecutor::GetManagedBrowser
T 2014-02-13 12:19:54:565 response.cc(43) Entering Response::Serialize
T 2014-02-13 12:19:54:566 IESession.cpp(217) Found non-zero response length
T 2014-02-13 12:19:54:566 IECommandExecutor.cpp(185) Entering IECommandExecutor::OnGetResponse
T 2014-02-13 12:19:54:566 IECommandExecutor.cpp(290) Entering IECommandExecutor::OnIsSessionValid
D 2014-02-13 12:19:54:566 server.cc(308) Response: {"sessionId":"912c7d96-669e-47d6-b10d-66aae627f1ff","status":16,"value":{"message":"Unable
to add cookie to page"}}

T 2014-02-13 12:19:54:566 server.cc(359) Entering Server::SendResponseToClient
T 2014-02-13 12:19:54:566 response.cc(32) Entering Response::Deserialize
T 2014-02-13 12:19:54:566 server.cc(451) Entering Server::SendHttpInternalError

Reported by anandj82 on 2014-02-13 06:55:04

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 6985 may also be related.

Reported by sitsofe on 2014-02-14 06:12:57

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

comment 37 was for IE 8.0. It works fine in IE10 

Reported by anandj82 on 2014-02-14 12:53:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

anandj:
Could you also capture and add here the full HTTP headers for the problem page e.g.
the output of
curl -D - -o /dev/null 'https://sucs.org/~sits/test/selenium/ie9header/'
if you were on Linux etc.

Reported by sitsofe on 2014-02-23 08:12:32

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@sits
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1
200 OK
t-srvr: Mon Feb 24 00:39:08 CST 2014
s-srvr: aixwcs486p.prod.ch4.s.com, prdb3
P3P: CP=CAO PSA OUR
Pragma: No-cache
OM_pathInfoOmniName: CmsContentView
s-cs: 0
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
s-srvr: aixwcs486p.prod.ch4.s.com, prdb3 ;akamai_cache
Cache-Control: private, max-age=900
Expires: Mon, 24 Feb 2014 09:09:56 GMT
Date: Mon, 24 Feb 2014 08:54:56 GMT
Transfer-Encoding:  chunked
Connection: keep-alive
Connection: Transfer-Encoding

100 78483    0 78483    0     0  2090k      0 --:--:-- --:--:-- --:--:-- 2322k

Reported by anandj82 on 2014-02-24 08:58:56

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

anandj:
My copy IE8 dislikes the "Pragma: No-cache" header you posted - when the server sends
that header pressing the right mouse button and going to Properties reports a Type:
of Not Available.

Reported by sitsofe on 2014-03-02 19:04:58

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I confirm that with :
- selenium server 2.42.2
- IEdriver 2.42.0
- Windows 7 SP1 64B and IE 9.0.8112

a response header 'Cache-control : no-cache' prevent cookie to be set with the error
above ('Unable to get mime type for document')
However, its work fine with value 'private' or 'public' for example.
Just in case, logs available at https://code.google.com/p/selenium/issues/detail?id=6985#c9

PS : In properties, document type is well detected.

Reported by yannick.chabbert on 2014-09-04 18:34:35

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 6985 has been merged into this issue.

Reported by barancev on 2014-10-31 14:04:00

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reproduced:
https://saucelabs.com/tests/4519556b9ef645e9acaca1893862a4ec
https://saucelabs.com/tests/4519556b9ef645e9acaca1893862a4ec/automator.log

Reported by barancev on 2014-10-31 14:45:33

  • Status changed: Accepted

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I'd suggest to create a command line option "/dont-check-mime-type" that suppresses
MIME type checking.

Yes, this can cause (sometimes unrecoverable) errors if a user attempts to perform
an operation on a non-HTML document. But if a user sets this option she takes responsibility
on the consequences.

Preventing possible crashes in edge cases is not a sufficient reason to totally block
ability to perform an operation on a valid document (that looks suspicious).

Reported by barancev on 2014-11-01 16:40:59

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

barancev:

Can you summarise what you did and what you found in your saucelabs logs? It's impossible
to see them without a saucelabs login and they might be of use to people in the future...

Reported by sitsofe on 2014-11-02 08:03:10

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Nothing new :)
"Unable to get mime type for document, call to IHTMLDocument2::get_mimeType failed"

Just confirmed that the issue still persists and suggested a solution to suppress MIME
type checking. That can cause unrecoverable errors if one attempts to set a cookie
to non-HTML page (e.g. a PDF document opened in the browser). But allows to set cookies
for valid HTML pages even if the browser can't determine MIME type of the page (because
the browser is old and buggy).

Reported by barancev on 2014-11-02 08:59:55

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@46 brancev:
Where should this "/dont-check-mime-type" be set? Should it be an option for IEDriverServer?

Reported by anandj82 on 2014-11-03 04:25:54

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

A command like option of IEDriverServer, or a capability.

Reported by barancev on 2014-11-03 10:57:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

This issue was closed by revision 511ac59049bc.

Reported by james.h.evans.jr on 2014-11-03 23:59:40

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have introduced capability to disable check of mime type of the document when setting
cookies in IE. I have done so despite the fact that omitting this check can cause unrecoverable
crashes in the driver. Evidence seems to indicate that the problem manifests itself
in legacy (<10) versions of IE, when a Cache-control header with the value "no-cache"
is set.

The new capability is "ie.validateCookieDocumentType", and when set to false, it skips
this check when adding a cookie. The default for this capability when it's unspecified
for a session is true; users setting this capability to false are considered to be
on their own when encountering issues setting cookies, including, but not limited to,
crashes in the driver executable.

Furthermore, I've also added a type safe option in the .NET InternetExplorerOptions
class to set this capability. Other language bindings will need updates from their
maintainers to provide similar type safe options.

Reported by james.h.evans.jr on 2014-11-04 00:06:22

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@52 james.h...

Thanks for the fix !
How could we test it because I didn't found yet IEDriverServer 2.44.0.1 release ?
(even if I fear I'm unable to test it until https://code.google.com/p/selenium/issues/detail?id=8160
is fixed)

Reported by yannick.chabbert on 2014-11-12 17:47:09

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

From the IEDriverServer.exe CHANGELOG (http://selenium.googlecode.com/git/cpp/iedriverserver/CHANGELOG)

    Version number notation guide:
    The version number of the IEDriverServer.exe is in the pattern as follows:

    major.minor.build.revision

    The "major" and "minor" fields are synchronized to releases of the Selenium
    project. Changes in the "build" field indicate interim releases made publicly
    available via the project downloads page. Changes in "revision" field indicate
    private releases checked into the prebuilts directory of the source tree, but
    not made generally available on the downloads page.

Given that the version number change is in the fourth field (the "revision" field),
you can easily see that the version is not publicly released. It is, however, checked
into the prebuilt directory of the source tree, and as such, can be pulled via a git
clone, or retrieved via http://selenium.googlecode.com/git/cpp/prebuilt/Win32/Release/IEDriverServer.exe

Reported by james.h.evans.jr on 2014-11-12 17:55:24

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

     checked into the prebuilt directory of the source tree

Exactly what I was looking for, thanks

Reported by yannick.chabbert on 2014-11-15 09:51:09

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 8056 has been merged into this issue.

Reported by barancev on 2015-04-03 16:32:51

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue is reproducible on IEServer 2.45. WebDriver doesn't see cookies in IE.

Reported by nikolay.v.borisenko on 2015-05-13 12:36:49

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:11:54

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 2, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant