Ibexy I
Ibexy I

Reputation: 1143

How Do I implement PhantomJS + Wedriver on c#

I have written the following code and downloaded PhantomJS intot he specified folder on c:\ but am getting the error: "Unable to connect to remote server ...". Here is the code I wrote:

[TestMethod]
public void HeadlessBrowser()
{
    IWebDriver driver = new PhantomJSDriver("C:\\trashStuff\\phantomjs-1.9.0-windows"); //or some other driver
    driver.Navigate().GoToUrl("http://yahoo.com");

    // Lets take a screenshot to really make sure we did visit the site above
    Console.WriteLine("Take A screen shot");
    Screenshot myScreenShot = ((ITakesScreenshot)driver).GetScreenshot();
    myScreenShot.SaveAsFile("c:\\trashStuff\\screenshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);


    // after the run, go to the location above and find screenshot.jpg
}

Upvotes: 3

Views: 2684

Answers (1)

Jonathan Kittell
Jonathan Kittell

Reputation: 7493

Download PhantomJS or add it to your project using NuGet Package Manager. I got it using NuGet and didn't have to put the path to the driver as one of the parameters in PhantomJSDriver class.

var driver = new PhantomJSDriver();

Upvotes: 1

Related Questions