Ad

'phantomjs' Executable Needs To Be In Path

- 1 answer

I have tried many ways to solve this problem but I kept on getting this error "'phantomjs' executable needs to be in PATH".

I have tried adding the path into the environment variable:

def __init__(self,base_url):
    self._phantomjs_path = os.path.join(os.curdir,'phantomjs/bin/phantomjs')
    self._base_url = base_url
    self._driver = webdriver.PhantomJS(self._phantomjs_path)

I expect the output of the weather forecast to be displayed. Can anyone help please?

Ad

Answer

@Guy is correct the phantomjs is depretiated so use either chrome driver or the firefox driver with the headless option, other options are available here but I have not tested them all yet.

Download chrome driver from here and add to PATH this is the code to use the chrome driver with the headless option.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)

base_url = "your_url_here"

driver.get(base_url)

driver.close()

Or for firefox driver download from here and add to PATH this is the code to use the firefox driver with headless option.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(options=firefox_options)

base_url = "your_url_here"

driver.get(base_url)

driver.close()
Ad
source: stackoverflow.com
Ad