0

I run this code and continually snag on the line: "IWebDriver Driver = new OpenQA.Selenium.Chrome.ChromeDriver();" When i run it this way, not directing to the ChromeWebDriver, I get: "the chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable."

When I give the path to the ChromeWebDriver I get this: "error CS1009: Unrecognized escape sequence"

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
  using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
 IWebDriver Driver = new OpenQA.Selenium.Chrome.ChromeDriver
 ("C:\Users\stand\Documents\
 Visual Studio 2015\Projects\WindowsFormsApplication2\ChromeWebDriver.exe");
             Driver.Navigate().GoToUrl("http://dallas.craigslist.org/");
        IWebElement Element = Driver.FindElement(By.Name("query"));
        Element.SendKeys("cx-5");

       }
   }
}
NineBerry
  • 26,306
  • 3
  • 62
  • 93

2 Answers2

1

Use

IWebDriver Driver = new OpenQA.Selenium.Chrome.ChromeDriver (@"C:\Users\stand\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\ChromeWebDriver.exe");

The Backslash has a special meaning in string literals. You could duplicate all backslashes or as in this example make the string literal to a "verbatim string literal" by adding the @ sign at the beginning. In verbatim string literals, the backslash has no special meaning


Another solution which means you don't have to manually specify the full path of the exe file can be found in this answer: Add the ChromeWebDriver.exe file to the project and choose to have it copied automatically to the same folder as your own application.exe.

Community
  • 1
  • 1
NineBerry
  • 26,306
  • 3
  • 62
  • 93
0

You need to either escape the backslashes in the path or use string literals.

IWebDriver Driver = new ChromeDriver (@"C:\Users\stand\Documents\Visual Studio 2015\Projects\WindowsFormsApplication2\ChromeWebDriver.exe");

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120