1

I want to use PhantomJS() in python3.4 and typed

Therefore:

from selenium import webdriver
browser = webdriver.PhantomJS()

I got the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/phantomjs/service.py", line 83, in start
    "Can not connect to GhostDriver on port {}".format(self.port))
selenium.common.exceptions.WebDriverException: Message: Can not connect to GhostDriver on port 40236

I know the error is thrown inside selenium.webdriver.phantomjs.service, because the function utils.is_connectable(self.port) can't connect to the localhost (the localhost is reachable).

try:
    self.process = subprocess.Popen(
        self.service_args, stdin=subprocess.PIPE,
        close_fds=platform.system() != 'Windows', 
        stdout=self._log, stderr=self._log)
except Exception as e:
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
count = 0
while not utils.is_connectable(self.port):
    count += 1
    time.sleep(1)
    if count == 30:
        raise WebDriverException("Can not connect to GhostDriver on port {}".format(self.port))

I couldn't find a solution that worked for me, so it would be create if someone has an idea.

My system:

Linux controller 4.1.15-v7+ #830 SMP Tue Dec 15 17:02:45 GMT 2015 armv7l GNU/Linux
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
S1J0
  • 179
  • 1
  • 6
  • 13

1 Answers1

0

you must download phantomJS - LINK

and after that give path to it in your code

browser = webdriver.PhantomJS(pathToPhantomJS)
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
  • 1
    @Barkan thanks for the reply, but phantomjs is installed and insert the path didn't worked either. – S1J0 Jan 13 '16 at 15:05