phantomjs icon indicating copy to clipboard operation
phantomjs copied to clipboard

Arg '--cookies-file' broken on 2.0

Open juanchristian opened this issue 11 years ago • 13 comments

I was trying this simple code using 2.0:

from selenium.webdriver.phantomjs import webdriver

driver = webdriver.WebDriver(service_args=['--cookies-file=cookies.txt'])
driver.get('http://google.com')
driver.quit()

The 'cookies.txt' file wasn't being created, tried many times, no lucky. Downgraded to 1.9.8 and bang, working 100%

juanchristian avatar Mar 28 '15 00:03 juanchristian

Hi,

I encountered the same issue. By changing one line in the "phantom.cpp" file I got it working, but I'm not sure if this is the correct way to do it (or if it will break existing code).

Change the the line in the Phantom::createCookieJar method from:
return new CookieJar(filePath, this);

to

return new CookieJar(m_config.cookiesFile() != "" ? m_config.cookiesFile() : filePath,this);

yali25 avatar Mar 30 '15 06:03 yali25

Are you sure? Because I don't see that line in phantom.cpp.

vitallium avatar Mar 30 '15 06:03 vitallium

I mean in this method:

https://github.com/ariya/phantomjs/blob/master/src/phantom.cpp#L297

yali25 avatar Mar 30 '15 06:03 yali25

Yes, maybe manually modifying the source can fix the issue. But people behind PhantomJS need to fix that!

juanchristian avatar Mar 31 '15 16:03 juanchristian

I met the same problem. 1.9.8 does working!

kunzhipeng avatar Feb 18 '16 03:02 kunzhipeng

I have the same problem.

chunfengd avatar Feb 23 '16 20:02 chunfengd

+1, Does anybody can fix it?

maZahaca avatar May 07 '16 11:05 maZahaca

Perhaps there is a problem with Ghostdriver. Because the plain PhantomJS script works.

vitallium avatar May 07 '16 11:05 vitallium

This is at line 310 now.

Yossi avatar May 31 '16 09:05 Yossi

I'm running into some serious issues because of this, and I would've expected functionality like this to be much more visible, and problematic for a lot of users. Is there perhaps some workaround I'm not aware of?

jantman avatar Mar 29 '17 11:03 jantman

The "workaround" is to compile it yourself after fixing the code the way @yali25 suggests.

Here's a wiki page with step by step instructions https://github.com/Yossi/agent-stats-utils/wiki/How-to-compile-phantomjs-for-yourself

Yossi avatar Mar 29 '17 11:03 Yossi

That "workaround" may be suitable for things that only use phantomjs locally, but it's certainly not for the acceptance tests of my open source project, which have to run on TravisCI as well as on the local machine of anyone who wants to develop the project.

For anyone else who has similar needs, I have come up with a workaround the solves the problem if your environment requires phantomjs, but has no control over the version or compilation. I'm using Selenium WebDriver in my tests, to wrap phantomjs. I've written some wrapper methods that are called to get a Browser instance and to request pages; after a page is requested (before teardown), I use WebDriver's get_cookies() method to retrieve a list/array of cookies and then serialize that to disk as JSON. When a new Browser is constructed and a page is first loaded, I deserialize the JSON and use add_cookie() to inject the cookies back into phantomjs. As far as I can tell, this works with any phantomjs version (and in theory should work with any other WebDriver-supported browser as well).

jantman avatar Apr 02 '17 12:04 jantman

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

stale[bot] avatar Dec 29 '19 11:12 stale[bot]