How to install Selenium for Python and C# - c#

I'm struggling to follow the directions for installing Selenium on a windows machine and I need it for both Python 7.5 and C# platforms.
I ran the command :
D:\selenium-2.37.2> D:\Python27\python setup.py install
And I get this:
Traceback (most recent call last):
File "setup.py", line 17, in <<module>>
from setuptools import setup ImportError: No module named setuptools
Setuptools? Errr... What is that? Of course I looked it up, but there is no way to get that in view of all that is advised.
Is there a sure-way of installing Selenium on Win 7 for python?.

Have you tried this Python 3: ImportError "No Module named Setuptools" ?
According to this post, it might work even better with easy_install.
Couldn't install pip and selenium in windows7

Windows 7:
1. Install PyCharm education Edition IDE with Python 2.7 (JetBrains: https://www.jetbrains.com/pycharm-educational/)
2. Setup easy install (windows - simplified)
a. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
b. move ez.setup.py to C:\Python27\
c. open cmd prompt
d. cd C:\Python27\
e. C:\Python27\python.exe ez.setup.py install
3. Setup selenium webdriver for python
a. Download selenium source code from pypi : selenium-2.45.0.tar.gz from https://pypi.python.org/pypi/selenium
b. unzip it using 7Z software
c. open cmd prompt
d. cd to selenium-2.45.0 unzipped directory
e. C:\Python27\python.exe setup.py install
4. Test selenium webdriver for python
a. Open PyCharm IDE
b. create a new python file with the following contents:
from selenium import webdriver
browser=webdriver.Firefox()
browser.get('http://seleniumhq.org/')
c. Run the python script
d. Firefox browser will open and navigate to the intended website
5. Done!

Related

selenium chromedriver is throwing a version error but version is matched [duplicate]

when i go to command prompt and type chromedriver -v:
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945#{#614})
but when i try to run this code :
from selenium import webdriver
class InstaBot:
def __init__(self):
self.driver=webdriver.Chrome()
self.driver.get("www.instagram.com")
InstaBot()
it gives me error like this:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
why this is happening i tried to remove selenium as well as chromedriver
and reinstall of version 79.0.3945 but when i run it ,it show this can only be run on version 80
my chrome version is 79.0.3945 which is lastest ,and version 80 chrome is chrome beta
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
...implies that the ChromeDriver v80.0 was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You mentioned about using chromedriver=79.0.3945.36 and the release notes of chromedriver=79.0 clearly mentions the following :
Supports Chrome v79
Presumably you are using chrome v79.0 browser.
So, it's quite evident your have chromedriver=80.0 present within your system which is also within the system PATH variable and is invoked while you:
self.driver=webdriver.Chrome()
Solution
There are two solutions:
Either you upgrade chrome to Chrome Version 80.0 level. (as per ChromeDriver v80.0 release notes)
Or you can override the default chromedriver v80.0 binary location with chromedriver v79.0 binary location as follows:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
You can find a detailed discussion in Ubuntu: selenium.common.exceptions: session not created: This version of ChromeDriver only supports Chrome version 79
Additional Considerations
Ensure to:
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Reference
You can find a relevant detailed discussion in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
Use Bonigarcia plugin in project. After that it will manage all driver by itself.It reads chrome version and instantiate driver accordingly.
for help follow my post :
https://www.linkedin.com/pulse/webdrivermanager-bonigarcia-rohan-ravi-yadav/
or original git link/post
https://github.com/bonigarcia/webdrivermanager
If any help required , Let me know

Error in library(data.table) : there is no package called 'data.table'

We have created a webservice on IIS which calls a R script. The R script includes some libraries like: data.table, caret and few a more. R is returning an error that it cannot find the data.table library:
"Error in library(data.table) : there is no package called
'data.table'".
We confirmed that the data.table package is installed in: "C:\Program Files\R\R-3.3.3\library\data.table". When we run .libPaths() to check where R tries to load the libraries from, it returns that this is the folder "C:/Program Files/R/R-3.3.3/library".
It does work successfully in a Visual Studio 2017 unit test or even in a console application environment. So the question is why can't R load the data.table library within IIS?
We using the following software versions:
R for Windows 3.3.3
Internet Information Services version 10.0.14393.0
RDotnet community 1.6.5
C# code:
R = REngine.GetInstance();
R.Initialize();
R.Evaluate("install.packages('data.table', repos='http://cran.us.r-project.org', dependencies = TRUE)");
R.Evaluate("library(data.table)");
We have decided to switch to 'Microsoft R Open' (MRAN) instead of R for Windows (CRAN). This solved a lot of problems for us. We couldn't get CRAN to work with IIS.
Only thing we need to do with MRAN is give the user the IIS application is running on modify access to the library folder at "C:\Program Files\Microsoft\R Open\library". This is needed to enable the R-engine within our application to install R-libraries.

Selenium 2.53.1 does not work on FireFox 48

I am using selenium to test our websites. When I build the project, there is an Exception :-
OpenQA.Selenium.WebDriverException: Failed to start up
socket within 45000 milliseconds. Attempted to connect to the
following addresses: 127.0.0.1:7055 and the problem is from the code
IWebDriver driver = new FirefoxDriver();
Anybody knows how to solve this problem?
Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable that will run alongside the browser.
You can download the latest executable geckodriver from here
Add downloaded executable geckodriver to system path
The Selenium client bindings will try to locate the geckodriver (or wires) executable from the system path. You will need to add the directory containing the executable to the system path.
On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
On Windows you need to update the Path system variable to add the full directory path to the executable geckodriver. The principle is the same as on Unix.
After all above stuff you need to Initialize FireFoxDriver as below :-
var driver = new FirefoxDriver(new FirefoxOptions());
Note :- Follow this link for the solution of this problem with other programming language.
This answer didn't worked with me. Running selenium 2.53.6 and firefox 47 n 48.
I would recommend downloading firefox 46 which seems to be the best match for selenium 2.53.x.
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
Once I downgraded to firefox 46.0.1 everything was working as expected.

ActiveX DLL Error

OK while I never thought in 2012 I would be writing my first ActiveX control (and yes there is a good reason for it) I am struggling with getting it running under Windows 7 (x64).
The Solution Short Story: I was missing /codebase from some of my regasm calls and also mixing up 32 and 64 bit processes, but that wasn't being helped by the standard VS2010 command prompt mixing up 32 and 64 bit paths for regasm and cscript.
The long story follows:
I have been bouncing between
Creating an ActiveX control in .Net using C#
(Oops I had the wrong link .. although it looks like the link I initially supplied was someone copying the original blog page)
Creating an ActiveX control in .Net using C#
and
C# ActiveX control (CSActiveX)
And I appear to be building the projects successfully (for the latter one I had to change the resource compiler location to the correct location).
For the first project I am using the suggested installer, for the second project I am trying to use regasm directly.
But after this it all goes down hill. I try and register the all's but either:
I have no idea how I should be registering them, or:
I have no idea how I should be registering them.
My test case has been a simple JScript file containing
var x = new ActiveXObject( "name of object" );
Which fails with the error:
test.js(1,1) Microsoft JScript runtime error: Automation Server can't create object
I am not sure if this is a permissions issue, or a 32 vs 64 bit issue or a combination.
A lot of sites offering help on ActiveX are assuming you will be accessing it via a web page , so I have tried looking at IE permissions (even though I want to load the control into a 3rd part program).
I know if I use either the 'framework' or 'framework64' versions of regasm I can control where in the registry entries get put - and I have seen some references to running cscript as either 32 or 64 bit (which possible affects what part of the registry is searched) depending on the cmd shell invoked (and I have tried both ways, as well as trying an "administrator" shell).
So basically at this point I have no idea what I am doing or what I should be doing.
My goal is to register an ActiveX control on Windows 7 x64 and have it be able to be loaded by:
A test .js script running from the default Windows command prompt
Load the same control into something like Excel 2007 VBA (for testing only)
Load the control into a 3rd part application (RSView Studio from Rockwell) and have it hosted within a VBA application (and I need to check if this isa 32 or 64bit program .. I suspect the former)
Notes
For the project that users the installer (Creating an ActiveX control in .Net using C#), it installs the code into "c:\program Files (x86)\" and looking with regedit I find entries under "Computer\HKEY_CLASSES_ROOT\Wow6432Node\CLSID\" which I believe is telling me that the DLL was installed as a 32 bit process. I have tried running my cscript test from both a 32 and 64 bit cmd and they both fail. NOTE that the installer was creating the equivalent of "regasm /codebase" when it ran.
For the project where I tried using regasm to register it (C# ActiveX control (CSActiveX)), it has some additional code for registering an ActiveX COM control. This code mentions registering 32 bit in-process servers (see ActiveXCtrlHelpers.cs)
(BTW I'm also cursing auto correct in Safari/Lion at the moment, keeps changing lower case "DLL" into "all")
Edit 2012-08-07
Prompted by Art's answer I discovered:
From standard VS2010 command prompt
When running 'regasm /codebase' through the standard VS2010 command prompt (and as administrator to allow regasm to perform changes), the entries got dumped into the registry under HKEY_CLASSES_ROOT\Wow6432Node\CLSID and the test scripts failed from the same prompt.
However I can see the ActiveX control in Excel 2007 (32 bit)
From x64 Win64 VS2010 command prompt
When running under the VS2010 x64 Win64 command prompt (again as admin) the registry entries appeared under HKEY_CLASSES_ROOT\CLSID but this time the test scripts worked from the same prompt and also from a standard Windows cmd prompt (however they fail from a 32 bit prompt)
But!! I can't see the active X control from Excel 2007 (32 bit)
Now I just need to figure out what the windows equivalent of the *nix 'which' command to ensure which regasm I am using) the 'where' command
Looking at the VS2010 and Windows 7 command prompts:
VS2010 (standard prompt): cscript => c:\windows\system32\cscript.exe
regasm => c:\windows\Microsoft.net\framework\v4.0.30319\regasm.exe
VS2010 (x64 Win 64): cscript => c:\windows\system32\cscript
regasm => c:\windows\Microsoft.net\framework64\v4.0.30319\regasm.exe
Windows 7 std. prompt: cscript => c:\windows\system32\cscript.exe
Windows 7 32 bit prompt: cscript => c:\windows\SysWOW64\cscript.exe
This is all starting to make some of my confusion understandable. I have been unknowingly mixing and matching 32 and 64 bit systems, but the VS2010 standard prompt didn't help either!
(and my latest peeve - VS2010 saving files as UTF-8 with BOM)
I was able to make this work both via IE and vbscript by doing the following:
Create .NET class library named 'ActiveXTest'
Add a class named MyObject which is defined as follows:
namespace ActiveXTest
{
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ProgId("ActiveXTest.MyObject")]
[System.Runtime.InteropServices.Guid("df2dac4d-ba8a-4ecc-b76e-958c1bc32f1f")]
public class MyObject
{
public string HelloWorld()
{
return "This is Hello World from the COM component!";
}
}
}
Compile the class. Go to the folder where you compiled the class and do the following from a Visual Studio command prompt: regasm /codebase ActiveXTest.dll
To test from a .vbs script, create a file in notepad call test.vbs. type the following into the file:
Dim myObject
set myObject = CreateObject("ActiveXTest.MyObject")
MsgBox(myObject.HelloWorld)
Open a command prompt and navigate to where where you created the Test.vbs and type: wscript test.vbs. A dialog should be displayed stating "This is Hellow World from the COM component"
To test this from IE, I created a TEST.HTML file with the following contents:
<HTML>
<HEAD>
<script language="JScript" language="JavaScript">
var obj = new ActiveXObject("ActiveXTest.MyObject");
alert(obj.HelloWorld());
</script>
</HEAD>
<body>
<span>nothing to see here!</span>
<body>
</HTML>
Open the TEST.HTML file in IE. You will get a warning about the ActiveX control; just say Yes to allow the interaction. You will get an alert dialog stating "This is Hello World from the COM Component".
Similar steps can be used to make it work from a .js file or from Excel VBA. Note that if you change the COM method signature of the ActiveX assembly I believe you will need to re-register it.

Use chrome with Selenium 2.0 with C#

I have a problem with the ChromeDriver.exe When I run the test, a Google Chrome Window is open but then an error from the chromedriver console shows up. It says something like:
[0405/175241: WARNING:scoped_temp_dir.cc<15>] Could not delete temp
dir in dtor.
Can anybody help me?....I'm Using C# by the way.
I wanned to upload an image but I couldn't because I'm a new user...
-JM
Selenium WebDriver C# in ChromeDriver:
Prerequisite: Install Visual Studio (mine is VS 2017), Google Chrome browser
Steps to follow:
Open VS 2017 and create solution/project
Write a test using C# code as below:
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("Your Test URL");
Now install "Selenium.WebDriver.ChromeDriver" by following steps:
Right click on Project -> Manage NuGet Packages...
Click Browse at the top and search for ChromeDriver
Select "Selenium.WebDriver.ChromeDriver" and install it
Execute/Run your test
Instead of moving your chromedriver.exe, when creating a new instance of a ChromeDriver you may put the exe's file path as a parameter. This is the same as for IE.
For example: driver = new ChromeDriver("C:\ChromeDriverFolder"); will look for the cromedriver.exe in a folder on the C drive called 'ChromeDriverFolder'.

Categories