0

I use phantomjs + python selenium for testing(the reason is that phantomjs can run without GUI, which could be easily deployed on Linux), there are several separate domain pages, each has their own cookie values, such as

A.com ===> cookie_A
B.com ===> cookie_B
C.com ===> cookie_C
D.com ===> cookie_D

I can set the A.com's cookie when I build the browser,

self.profile['phantomjs.page.customHeaders.Cookie'] = cookie_A

the question is that A.com might has some javascript which will just jump to B.com or C.com or D.com, I also need to set B.com or C.com or D.com's cookie for this, what is the elegant way to do this? I could not setup all cookies value when building the browser, as in the real case, there might be too many cookie values.

python
  • 1,870
  • 4
  • 24
  • 35

1 Answers1

1

I think you need Network Monitoring, something like that:

var page = require('webpage').create();

page.onResourceRequested = function(request) {
  page.addCookie( cookie_A);
};

page.open(url);
stdob--
  • 28,222
  • 5
  • 58
  • 73