1
votes

When I goto the following link on firefox (V-12), the browser on my Ubuntu machine allows me to login normally.

https://r.espn.go.com/members/v3_1/login?language=en&forwardUrl=&appRedirect=http%3A%2F%2Fgames.espn.go.com

However, if I use watir-webdriver, I get the message: "Cookies must be enabled in order to login."

Here is the code to reproduce this issue with Watir:

require 'watir-webdriver'
browser = Watir::browser.new
browser.goto "https://r.espn.go.com/members/v3_1/login?language=en&forwardUrl=&appRedirect=http%3A%2F%2Fgames.espn.go.com"

You will notice that the browser displays the "Cookies must be enabled" error message below the "email address or member name" field. When I looked at the cookies stored, I noticed that not all cookies that were stored in the normal mode are available. I compared this by searching for "go.com" in the stored cookies.

Any idea what would cause the discrepancy in cookies stored between the two modes, using the same browser?

Thanks!

1
I found this to be more of a website issue. I was able to get around this problem by clicking on "Sign In" and login in the pop-up box. It looks like the website writes some cookies when it comes from the main URL to the login URL which was getting skipped by going directly to the login URL.Sridhar S

1 Answers

3
votes

There is no problem or discrepancy with watir-webdriver. What is happening here is a result of how the website is coded.

The page you are accessing (https://r.espn.go.com/members/v3_1/login?language=en&forwardUrl=&appRedirect=http%3A%2F%2Fgames.espn.go.com) is intended to be an overlay on http://espn.go.com. Whoever coded the site assumed that the overlay page would always be accessed after a hit to the main page. So, the main page (http://espn.go.com) sets a cookie in order to test whether your user agent has cookies enabled. The overlay page with the sign in form then checks to see if the test cookie is present and, if not, displays the warning you are seeing.

What is important to understand is that watir-webdriver defaults to a clean profile for each new browser instance. This means that the browser does not have any of your cookies, extensions, preferences or browsing history. Because the clean profile has never visited http://espn.go.com to receive the test cookie, the warning is being displayed.

There are two ways to avoid this warning:

  1. You can visit the main page prior to the sign-in page, like so:

    require 'watir-webdriver'
    browser = Watir::Browser.new
    browser.goto "espn.go.com"
    browser.goto "https://r.espn.go.com/members/v3_1/login?language=en&forwardUrl=&appRedirect=http%3A%2F%2Fgames.espn.go.com"
    
  2. Or, you can use your default Firefox profile, which (presumably) already has the test cookie:

    require 'watir-webdriver'
    browser = Watir::Browser.new :firefox, :profile => "default"
    browser.goto "https://r.espn.go.com/members/v3_1/login?language=en&forwardUrl=&appRedirect=http%3A%2F%2Fgames.espn.go.com"
    

Hope that helps!