sourcegraph / go-selenium

Selenium WebDriver client for Go
https://sourcegraph.com/github.com/sourcegraph/go-selenium
Other
367 stars 73 forks source link

Adding Cookie Before Load? #7

Closed lxcodes closed 9 years ago

lxcodes commented 9 years ago

Currently attempting to load a cookie before the loading of the page / browser but having issues. Is this possible or am I doing this wrong? Rather new to golang.

cookie := selenium.Cookie{"domain_splash", "1", "/", ".domain.com", false, 0}
webDriver.AddCookie(&cookie)
sqs commented 9 years ago

I am on vacation and not at my computer for another week but that seems right to me. I can pull up the snippet we use in our private code base if you still haven't gotten it to work by next Wed (please remind me by posting again then).

One thing I ran into with setting cookies (which is what you are probably encountering too) is that you do need to be on the same domain in the browser already. So we made our app return a quickly loading blank page at /cookietest and navigated to that in Selenium before setting cookies. This is a browser restriction not a Selenium or go-selenium restriction. (Otherwise how would know which domain the cookie was for?)

lxcodes commented 9 years ago

Makes sense on the second part there. I'll try to investigate and report back. Will need to ask the devs to add something in.

We are currently avoiding our splash screen using a javascript snippet for window.goBack() for now which seems to be working rather reliably -- Just extra load time is all. =]

Closing for now with the work around for me and I believe that the second paragraph from @sqs holds the key to the issue. Thanks for the reply @sqs!