1
options = webdriver.ChromeOptions()

#options.add_argument('-headless')
browser = webdriver.Chrome(executable_path="./chromedriver", options=options)

browser.get("http://127.0.0.1:8080/")
print browser.title
browser.find_element_by_name('username').send_keys("admin")
browser.find_element_by_name("password").send_keys("hunter2")
browser.find_element_by_tag_name("button").click()
print browser.get_cookies()
print 'loading another page: ' + url
#example url = example.com
browser.get(url)

I'm trying to do an automated test involving CORS. So, my requirement is I login to domain A successfully and get some cookies set. This works, and I see the cookies set when I do get_cookies(). Next, I navigate to another domain B, which makes a CORS request to domain A (all CORS headers are properly set, and tested manually). But this request fails because it appears that when I navigate to domain B, the cookies are cleared, so the request is unsuccessful.

Is there any way to force cookies to not clear ?

Note : same behavior with Chrome and Firefox driver on OSX

asudhak
  • 2,929
  • 4
  • 22
  • 27
  • 1
    Where are u declaring url? where are u checking new url cookies? – DarkSuniuM Oct 05 '18 at 15:59
  • can you check manually if the cookie is per session, meaning when you navigate to siteB session from siteA is terminated and cookie got deleted. – Infern0 Oct 05 '18 at 16:02
  • @DarkSuniuM : URL is obtained as a param to the function (not shown here) Checking the cookies is done manually since i'm not running this headless (for testing) – asudhak Oct 05 '18 at 16:06
  • @Infern0 - In the chrome process that is opened by driver, the cookies are not cleared if I test manually. it appears that, it only gets cleared by selenium when `browser.get(url) ` is called and URL is a different domain. – asudhak Oct 05 '18 at 16:10
  • @asudhak You havn't provided any information for us to do our analysis. Can you update the question with your binary information and the _Manual Steps_ you are trying to _Automate_ along with the relevant _HTML_ and the error you are seeing? – undetected Selenium Oct 05 '18 at 21:27

1 Answers1

1

Use browser.navigate().to(url) instead of get().

Credits: https://stackoverflow.com/a/42465954/4536543

Maxim Mazurok
  • 3,856
  • 2
  • 22
  • 37