title: Selenium: Trying to log in with cookies - "Can only set cookies for current domain"
body: <p><strong>What I am trying to achieve</strong></p>
  
  <p>I am trying to log in to a website where cookies must be enabled using Selenium headless, I am using PhantomJS for driver.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>I first recorded the procedure using Selenium IDE where it works fine using Firefox (not headless). Then I exported the code to Python and now I can't log in because it's throwing an error saying "Can only set Cookies for the current domain". I don't know why I am getting this problem, am I not on the correct domain?</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.by import By
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.support.ui import Select
  import unittest, time, re
  
          self.driver = webdriver.PhantomJS()
          self.driver.implicitly_wait(30)
          self.base_url = "https://login.example.com"
  
          driver = self.driver
          driver.get(self.base_url)
  
          all_cookies = self.driver.get_cookies()
  
          # It prints out all cookies and values just fine
          for cookie in all_cookies
              print cookie['name'] + " --&gt; " + cookies['value']
  
          # Set cookies to driver
          for s_cookie in all_cookies:
              c = { s_cookie['name'] : s_cookie['value']}
              # This is where it's throwing an error saying "Can only set Cookies for current domain
              driver.add_cookie(c)
  
          ...
  </code></pre>
  
  <p><strong>What I've tried</strong></p>
  
  <p>I've tried saving the cookies in a dict, going to another domain, going back to original domain and added the cookies and then trying to log in but it still doesn't work (as suggested in <a href="https://stackoverflow.com/questions/22507204/selenium-cookie-with-another-domain">this thread</a>)</p>
  
  <p>Any help is appreciated.</p>