GhostDriver with PhantomJS and Selenium (Python) - "Connection refused"

Purpose:

I am trying to do some curettage in Python using a mute browser: Selenium with PhantomJs and GhostDriver.

I am using Python 2.7 on a Mac running with Mavericks. I work in emacs (although it also did not work from the terminal). I have already overcome some errors, such as "phantomjs - there is no such file or directory exists", but you have the latest binaries from here that promise to be the last, including the pending patch from the official PhantomJS team.

My Script Test:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
        'phantomjs.page.settings.loadImages' : True,
        'phantomjs.page.settings.resourceTimeout' : 10000,
        'phantomjs.page.settings.userAgent' : "my_user_agent"
        }

driver = webdriver.PhantomJS(executable_path= "/usr/local/bin/phantomjs", desired_capabilities=desired_cap)
driver.set_window_size(1024, 768)
driver.get('https://google.com/')

driver.save_screenshot("testing.png")
driver.page_source("source_code.txt")

element = driver.find_element_by_xpath('--*[@id=-gbqfq-]')
element.send_keys('testing')
element.send_keys(Keys.ENTER)

Here is a link to a simple webdriver explanation: http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_phantomjs/selenium.webdriver.phantomjs.webdriver.html

Error message:

The error message I received

:

, - , . ... a

phantomjs service.py, . , :

self.process = subprocess.Popen(self.service_args, stdout=self._log, stderr=self._log) to:

self.process = subprocess.Popen(['/usr/bin/env', 'phantomjs', '--webdriver=59202'])

--webdriver . , , ghostdriver, ghostdriver.log . , , , - .

:

- , ?

+4

Source: https://habr.com/ru/post/1608735/


All Articles