Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start PhantomJS with commandline options in Selenium?

I can't find how to start phantomjs with command-line options like --cookies-file=/path/to/cookies.txt and other...

Tried driver = webdriver.PhantomJS('--cookies-file=/tmp/ph_cook.txt') but nothing.

For unknown reason add_cookie don't work to keep logged.

I tried to start phantomjs like this:

driver = webdriver.PhantomJS(executable_path = "phantomjs --cookies-file=/tmp/ph_cook.txt --webdriver")

but getting error:

raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghost driver.
like image 838
gooftime Avatar asked Dec 22 '14 22:12

gooftime


1 Answers

You can pass commandline arguments to the PhantomJS instance behind the scenes by passing them as a list to the service_args argument:

webdriver.PhantomJS(service_args=['--cookies-file=/tmp/ph_cook.txt'])

If the driver cannot be started then the language bindings are probably not able to determine the location of the PhantomJS executable properly. You may need to additionally pass the complete path to the executable_path argument. Note that if you installed PhantomJS through npm, the actual executable is not directly in the global package directory but in a subfolder of it.

like image 62
Artjom B. Avatar answered Sep 23 '22 00:09

Artjom B.