Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium.PhantomJS is invalid namespace

I am really trying my best to find a way to web scrape a website using javascript to load the pages so I can scrape lets say my playlist for example. I have had no luck with chrome driver nor phantomjs. Please have a look below and see if you can help me with the error.

using OpenQA.Selenium;
//The type or namespace 'PhantomJS' does not exist in the namespace 'OpenQASelenium'
using OpenQA.Selenium.PhantomJS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace MusicScaper
{
    class TidalScraper
    {
    }
}

My packages.config file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="HtmlAgilityPack" version="1.8.7" targetFramework="net461" />
  <package id="PhantomJS" version="2.1.1" targetFramework="net461" />
  <package id="Selenium.Support" version="3.14.0" targetFramework="net461" />
  <package id="Selenium.WebDriver" version="3.14.0" targetFramework="net461" />
</packages>
like image 317
steve Avatar asked Sep 21 '18 10:09

steve


2 Answers

The .NET language bindings marked the PhantomJS driver classes deprecated in 3.11, and those classes were removed in 3.14. The PhantomJS project and its driver are no longer being maintained, and the driver code has not (and will not) be updated to support the W3C WebDriver Specification. The preferred “headless” solution is to use Chrome or Firefox in headless mode, as both of those browsers and their drivers support such an operating mode. Alternatively, if you have your heart set on PhantomJS, and you don’t care about cross-browser execution, you can simply use the PhantomJS executable and automate it through its internal JavaScript API.

like image 70
JimEvans Avatar answered Oct 09 '22 23:10

JimEvans


So the simple answer to fix your issue is that when install the Selenium.WebDriver Nuget Package make sure its on version 3.11.2 as PhantomJS driver classes were removed in 3.14 (Had the exact same problem) as is no longer maintained.

like image 36
Egli Becerra Avatar answered Oct 09 '22 21:10

Egli Becerra