So i am working an a small testing tool using PhantomJS in python with selenium and the website i'm using it on uses the following script to determine if cookies are enabled or not
var tc = 'testCookie' + Math.round(Math.random() * 1e10);
window.document.cookie = tc;
cookiesSupported = (window.document.cookie.indexOf(tc) != -1) && window.navigator.cookieEnabled;
and when i open the app using phantomJS it tells me that cookies are not enabled although the documentation states that since Phantomjs 1.7 cookies are enabled by default.
Could anyone tell me exactly what am I doing wrong?
This is a snippet of my python code
def setUp(self):
headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0',
'Connection': 'keep-alive'
}
for key, value in headers.iteritems():
webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = value
webdriver.DesiredCapabilities.PHANTOMJS[
'phantomjs.page.settings.userAgent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
self.driver = webdriver.PhantomJS(executable_path='C:\\Users\\name\\Desktop\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
self.driver.implicitly_wait(30)
self.verificationErrors = []
self.accept_next_alert = True
def test_activation_activity(self):
driver = self.driver
driver.get("http://localhost/test_page.html")
sleep(10)
driver.save_screenshot('screen2.png')
Note that the test_page.html is only a page to see if the code works (it's not the actual application) and uses the same code that prints the cookiesSupported
variable
Note2 I tried the suggestion here using driver.cookies_enabled = True
but it doesn't work
EDIT: Is it possible the cookie checking method is incorrect? For example if I use the top answer from here it displays True even if I use PhantomJS