Wednesday, 10 September 2014

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

Click Here to OpenChromeBrowserUsingSeleniumWebDriverTool.zip

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#.

In previous article we learned How to Open Internet Explorer and Firefox Browser using selenium 'WebDriver'.

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.

Here are steps to learn How to Open Chrome Browser.


STEP 1 : First create new 'WebSite', after creating new 'WebSite' add selenium webdriver dll and also add new page. On this previous article your learn this.

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.

STEP 4 : Open your new page code file. Import selenium 'namespaces' and write following code on 'Open Chrome Browser' button click event.

Code File :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Selenium;
using OpenQA;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOpenChrome_Click(object sender, EventArgs e)
    {
        string STR_DRIVER_PATH = Server.MapPath("EXEFiles");
        OpenQA.Selenium.Chrome.ChromeDriver objCD = new OpenQA.Selenium.Chrome.ChromeDriver(STR_DRIVER_PATH);
    }
}

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.

[Image : Run Website and open Page] :

Selenium C# : How to Open Chrome Browser using selenium webdriver with ASP.Net C#
(To view original size image , click on image)


[Image : Chrome Browser Opened] :

Selenium C# : How to Open Chrome Browser using selenium webdriver with ASP.Net C#
(To view original size image , click on image)

Full Video : 



10 comments:

  1. Hello,
    Is it possible to run this once published on server?
    I tried but wihout any luck. It just spins whn press the button.
    Thank you!

    ReplyDelete
    Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. This is really informative article for new learner. Author explained all the things very nicely in this article and everyone can easily understand it. Really appreciated

    Now buffalo website design service is available from Crystal Tech Solution in a professional way.

    ReplyDelete
  3. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
  4. I learned World's Trending Technology from certified experts for free of cost. I Got a job in decent Top MNC Company with handsome 14 LPA salary, I have learned the World's Trending Technology from python training in btm layout experts who know advanced concepts which can help to solve any type of Real-time issues in the field of Python. Really worth trying instant approval blog commenting sites

    ReplyDelete

  5. your post is really very interesting to read. I got Very valuable information from your blog.
    Best Python Training in BTM Layout

    ReplyDelete
  6. Thanks for sharing your innovative ideas to our vision. I have read your blog and I gathered some new information through your blog. Your blog is really very informative and unique. Keep posting like this. Awaiting for your further update.If you are looking for any Data science related information, please visit our website Data science training institute in bangalore

    ReplyDelete