Wednesday, 10 September 2014

Selenium C# : How to Open Chrome Browser using selenium webdriver with ASP.Net C#

Note : If any runtime error occurred by running our downloaded project meaning of that your browser version and Selenium API DLL version is not matching. To resolve this issue you need to download latest Selenium C# API DLLs from this link and paste downloaded DLLs into 'Bin' folder of downloaded project. Or you can remove references of existing DLLs references and add new DLLs references. You can learn this thing from this link.

We can also open Chrome Browser programmatically using selenium C# 'WebDriver' API with ASP.Net C#.

For opening or launching Chrome is different from Open 'FF'. In that we need one extra EXE file named 'chromedriver.exe' file.

If you Do not have 'chromedriver.exe' file file at that time Code gives us an error like :

An exception of type 'OpenQA.Selenium.DriverServiceNotFoundException' occurred in WebDriver.dll but was not handled in user code.

Additional information: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html.

STEP 2 : Now, you need special Executable (EXE) file named "chromedriver.exe". You can download this file from this URL : http://chromedriver.storage.googleapis.com/index.html. You can choose latest version folder on this link. Or you can also get this file from our project by downloading project source code.

STEP 3 : After downloading file, Add new folder in your 'website' or project, named it 'EXEFiles' and copy your downloaded file 'chromedriver.exe' in this folder.

Explanation : In this code you can see that First we set path of 'chromedriver.exe' file, in which folder we save this file. After that, we create object of 'ChromeDriver' class to open Chrome browser, which exist in 'OpenQA.Selenium.Chrome' namespace. You can see that in constructor of 'ChromeDriver' class we supply 'CHROME_DRIVER' Path.

STEP 5 : Run the website. After Default page is appeared in browser, this website may run in any browser. You click on 'Open Chrome Browser' button. It will Open Chrome Successfully.