www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Firefox SeleniumIDE can not read cookies

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    4

    resolved [RESOLVED] Firefox SeleniumIDE can not read cookies

    Hello, I am working with a website written with asp.net. The problem is with reading cookies on a page. When I use Firefox's cookie viewer plug-in, I can see the cookies.. and remove them.
    However, when I use SelenuimIDE, another great Firefox plugin designed to run automated cookie tests, it does not see the cookies that I can see through the cookie viewer I mentioned.
    I ran a test javascript snippet using Firefox's scratchpad directly on the page, see below, to see if it it can read/set the existing cookies' values, but it fails to read/set. (doesn't see them)

    Then I decided to create a new cookie on the page directly through the scratchpad tool in Firefox without a post-back and succeeded. The new cookie "username" created in such a way was successfully read by SeleniumIDE

    I have noticed in the cookie viewer that the path for "username" was different from all other cookies. For ex, the path for all cookies except the "username" is "/" however the "username"'s path is "/DNN1.1.1/" . I went into the C# code and set the same path for other cookies that previously had the default path "/". I was able to see that path in the cookie viewer after running the postback. However, despite the fact that the "username" cookie and other cookies look exactly the same in the cookie viewer, including the path, SeleniumIDE still fails to read them except for "username" that I created directly on the page using the scratchpad tool.



    What could be the problem. Thank you.


    function getCookie(c_name)
    {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
    x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
    y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
    x=x.replace(/^\s+|\s+$/g,"");
    if (x==c_name)
    {
    return unescape(y);
    }
    }
    }

    var username=getCookie("username");
    if (username!=null && username!="")
    {
    alert("Welcome again " + username);
    }
    else
    {
    username=prompt("Please enter your name:","");
    if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
    }
    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    use locatStorage instead of cookies.

  3. #3
    Join Date
    Nov 2011
    Posts
    4
    learne donce again...complexity is only a percieved structure. Before delving in the advanced troublshooting techniques I had to check the sap.net cookie object on MSDN and learn that there is HttpOnly property that : "Gets or sets a value that specifies whether a cookie is accessible by client-side script."

    source:
    http://msdn.microsoft.com/en-us/libr....httponly.aspx

  4. #4
    Join Date
    Nov 2011
    Posts
    4
    thank you rnd me, how will localStorage help me resolve the problem I have described?
    thank you

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by safewebber View Post
    thank you rnd me, how will localStorage help me resolve the problem I have described?
    thank you
    localStorage is newer and doesn't have the same implementation complexities as cookies. i can see why an IDE would want to take over cookies, but i would bet they keep their hands off localStorage since it's not required for server/client interaction.

    just a guess on an otherwise quiet thread...

  6. #6
    Join Date
    Nov 2011
    Posts
    4
    ok, thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles