Warning: fopen(/tmp/SghXTngBZPli-qPs5sg.tmp): failed to open stream: Disk quota exceeded in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 139
Warning: unlink(/tmp/SghXTngBZPli-qPs5sg.tmp): No such file or directory in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 142
In this post we will discuss writing some simple code with Selenium C# in Visual Studio IDE. In the last post we referenced our Selenium WebDriver and Chrome driver via Nuget package manager in our project. Please read my previous post to get started with selenium referencing in Visual Studio IDE.
Once you are done with setup (referencing), you are all set you write a simple code.
Here is the code snippet
//Create the reference for our browser
IWebDriver driver = new ChromeDriver();
//Navigate to google page
driver.Navigate().GoToUrl("http:www.google.com");
//Find the Search text box UI Element
IWebElement element = driver.FindElement(By.Name("q"));
//Perform Ops
element.SendKeys("executeautomation");
//Close the browser
driver.Close();
In the above code snippet, we have
Created an instance for IWebDriver and got the instance for ChromeDriver
Navigate to Google home page
Found the Search textbox of google home page
Searched for execute automation by typing the text
Close the driver instance (which closes the chrome browser)
Here is the complete video for the above explanation
Thanks for watching the video and reading the post !!
Please leave your comments and let me know if there is anything need to be improved in the post !!!
Thanks,
Karthik KK
Post Author:
Karthik kk
24 Replies to “Simple code with Selenium C#”
Great article. Especially good for those just getting started writing C# to drive Selenium.
Thanks karthik, really useful for beginners. Appreciate your hard work for giving step by step information for free of cost though there are many sites charging lot of fee.
@ Vikas for the error ‘unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll’ go to the http://chromedriver.storage.googleapis.com/index.html
download the latest version and replace the chromedriver.exe in your project bin folder.
I also encountered the same error because I selected the wrong chrome driver (it is hard to know which is correct because there are 7 listed). I fixed it by installing the chrome driver which has the highest number of downloads.
when i try the same snippet from the current page i am getting an exception “An unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll” i am clue less why
Hi Karthik,
This is awesome article… i really liked it …. When i execute the code… i got excetion handling error…
In the code above at line 2 (IWebDriver driver = new ChromeDriver();)
Error -An unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll
What action need to be taken?
Your help is greatly appreciated.
deploy to chromedriver exe is not supported and the exe of file how to config in the deployment side and chrome driver and i make web api access to access the concept
all way completed but my problem deploy to execute web api in c# that is my question
Hi Karthik
i read your tutorial and create a selenium automation in asp.net,c# website. That project working fine on local system but project is deployed to server that project is not working and no gatting any error. I also read many website but i do not get a solution. So please help my issue.
Sir great But My question is How to run My html code with specific url with selenium web driver., now my i am using cefsharp web browser and cefsharpObject.HtmlLoad(“My Html code”,”URL That i want”,) this complete my task but getting time that is very bad my work,
Great article. Especially good for those just getting started writing C# to drive Selenium.
Karthik,
I just posted your URL for ExecuteAutomation.com to my website:
http://www.qa2100.com
Keep up the great work.
Bill
Thank you Bill.
Glad you like it and thanks for posting my site URL in your site.
Thanks,
Karthik KK
Thanks karthik, really useful for beginners. Appreciate your hard work for giving step by step information for free of cost though there are many sites charging lot of fee.
Thank you Sharvan !!!
Hi Karthik,
It really very nice and very useful for everyone. Could you please share some videos on Grid with C# so it will be complete.
Thanks
Gives ‘System.InvalidOperationException’ while creating the chrome driver instance (line no.3). However, works fine with FirefoxDriver.
sorry! line no 2 in the code snippet posted on this page.
@ Vikas for the error ‘unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll’ go to the http://chromedriver.storage.googleapis.com/index.html
download the latest version and replace the chromedriver.exe in your project bin folder.
Same with me. Karthik can you please tell us about the solution this.
Hi karthik,
Very good session.can u explain how to replace the chromedriver.exe in project bin folder
What do you mean replace ?
Can you please update to latest chrome driver via Nuget if you want to.
Thanks,
Karthik KK
I also encountered the same error because I selected the wrong chrome driver (it is hard to know which is correct because there are 7 listed). I fixed it by installing the chrome driver which has the highest number of downloads.
Hi Karthik,
when i try the same snippet from the current page i am getting an exception “An unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll” i am clue less why
Gives ‘System.InvalidOperationException’ while creating the Internet explorer driver instance (line no.3). However, works fine with ChromeDriver.
Hi Karthik,
This is awesome article… i really liked it …. When i execute the code… i got excetion handling error…
In the code above at line 2 (IWebDriver driver = new ChromeDriver();)
Error -An unhandled exception of type ‘System.InvalidOperationException’ occurred in WebDriver.dll
What action need to be taken?
Your help is greatly appreciated.
ERROR: Unable to locate element: {“method”:”name”,”selector”:”q”}
Hi Karthik,
How to Launch Private Mode IE browser with Selenium C#, I tried two ways but its not working, can you please help here
Method 1:
InternetExplorerOptions options = new InternetExplorerOptions();
options.BrowserCommandLineArguments = “-private”;
options.IgnoreZoomLevel = true;
driver = new InternetExplorerDriver(driverfolder,options);
Method 2:
driver.Navigate().GoToUrl(“about:InPrivate”);
driver.Navigate().GoToUrl(url);
deploy to chromedriver exe is not supported and the exe of file how to config in the deployment side and chrome driver and i make web api access to access the concept
all way completed but my problem deploy to execute web api in c# that is my question
hi Karthik,
I would like to purchase the selenium c# advanced course. could you please share the coupon code
Hi Karthik
i read your tutorial and create a selenium automation in asp.net,c# website. That project working fine on local system but project is deployed to server that project is not working and no gatting any error. I also read many website but i do not get a solution. So please help my issue.
Whats the issue ?
Sir,
How to initialise local google chrome driver ?
Sir great But My question is How to run My html code with specific url with selenium web driver., now my i am using cefsharp web browser and cefsharpObject.HtmlLoad(“My Html code”,”URL That i want”,) this complete my task but getting time that is very bad my work,