Re: [selenium-users] Create WebDriver C# script with built in .NET tools in Windows 7 (without VS2010)

748 views
Skip to first unread message

Shaba K

unread,
Nov 2, 2012, 8:16:54 AM11/2/12
to seleniu...@googlegroups.com
There are a external dll's you will have to add to your classpath.

Also make sure you create a lib folder add all necessary dll's on to there & add that to classpath that would be neat.

There is latest 2.26 released you can get that too.

Cheers,
S



On Thu, Nov 1, 2012 at 12:18 PM, Kamaldeep Batra <kamalde...@gmail.com> wrote:
I want to learn Selenium WebDriver C# scripting without downloading Visual Studio Express as previously I have been practicing C# program without any IDE. I added the path C:\Windows\Microsoft.NET\Framework\v3.5 to environment variable. Created the C# program file in notepad & saved it with .cs extension. Executed in cmd by cd to directory where program was saved. Ran command csc.exe program.cs

For Selenium webdriver I downloaded Selenium-dotnet-2.25.1 zip file. Right clicked the file, selected unblock. Unzipped this file. Downloaded Internet explorer server, IEDriverServer_x64_2.25.3.Now created a selenium practice file, selpractice.cs as:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;

namespace mySelenium
{
    class Program
    {
        static void Main()
        {
            IWebDriver driver = new InternetExplorerDriver(@"C:\Downloads\IEDriverServer_x64_2.25.3");
          
        }
    }
}

I compiled this by performing change directory to the directory where this program was saved. Executed by using dlls in selenium-dotnet-2.25.1 as references:

csc.exe selpractice.cs /r:C:\Downloads\selenium-dotnet-
2.25.1\net35\Castle.Core.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\Ionic.Zip.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\Newtonsoft.Json.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\Selenium.WebDriverBackedSelenium.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\ThoughtWorks.Selenium.Core.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\WebDriver.dll /r:C:\Downloads\selenium-dotnet-2.25.1\net35\WebDriver.Support.dll

There were no compilation errors. But on executing selpractice.exe get popup saying selpractice.exe has crashed. The logging information that I get in cmd window is :

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'WebDriver, Version=2.25.1.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f' or one of its dependencies. The system cannot find the file specified.
File name: 'WebDriver, Version=2.25.1.0, Culture=neutral,
PublicKeyToken=1c2bd1631853048f'
   at mySelenium.Program.Main()


Please help to make it work

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/c-5azZRgMDYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sirus tula

unread,
Nov 2, 2012, 9:40:56 AM11/2/12
to seleniu...@googlegroups.com
Not sure why you would want to use c#  without visual studio. The main reason of using VS is to help us debug problems if problems occur like you are having right now. I'm not sure how and where you can add references for c# without using visual studio.

Visual c#  2010 express is free version so you can use that otherwise you will be pounding your head to figure out the root cause of problem every time you hit the problem.

--
 
- "If you haven't suffered, you haven't lived your life."
 
Thanks,
 
Sirus

David

unread,
Nov 2, 2012, 1:49:19 PM11/2/12
to seleniu...@googlegroups.com
True that in today's world of IDEs, you'd want the IDE. But also good to know the traditional/core method of compilation (for C#, C++, and Java).

I haven't used Selenium in C#, but what the OP has executed for compilation looks correct in general. With the command line method, you add references as compile parameters just as the OP did.

The caveat, that I hope the OP has addressed is that even after compiling, you need to be sure the executable is able to reference the Selenium DLLs. I believe the compile time reference does not tell the executable where to find the DLL after it's compiled and executed. With an IDE, the IDE takes care of that (usually placinga copy of the DLL in your bin folder with the executable). Similarly, with the command line method, you need to place a copy of those DLLs where the executable is. The easy way to compile is to have all the source files and DLLs in a single location and compile with references from there so you have everything in one place. I believe .NET assemblies/executables find DLLs in the following locations (forget order precedence): local path of executable, the .NET Global Assembly Cache (GAC).

Also, if one is avoiding use of the VS IDE because it's bloated (I feel even the free Express edition is bloated), you can find a free lighter version of a .NET IDE in SharpDevelop (and there's also MonoDevelop).
Reply all
Reply to author
Forward
0 new messages