Selenium - Failed to Start Browser Session - Access Denied - XP - java

I'm getting the following error when starting up Selenium on XP
java.lang.RuntimeException:
Could not start Selenium session: Failed to start new browser session:
java.lang.RuntimeException: java.io.FileNotFoundException:
C:\Program Files\Mozilla Firefox (Access is denied)
Any thoughts?

Kind of stating the obvious, but it looks like Selenium is trying to read/write a Firefox profile but the system is blocking it. This could be because the Selenium user doesn't have appropriate security permissions, or possibly something else is locking access to a profile file.
You could try running the Sysinternals Process Explorer tools to identify what is getting in the way.
Firefox can block access to profiles to Selenium during the copy process, as is mentioned in this related answer.
You may also want to refer to the Selenium documentation in regards to profile handling:
Firefox will not run two instances
simultaneously unless you specify a
separate profile for each instance.
Selenium-RC 1.0 and later runs in a
separate profile automatically, so if
you are using Selenium 1.0, you can
probably skip this section. However,
if you’re using an older version of
Selenium or if you need to use a
specific profile for your tests (such
as adding an https certificate or
having some addons installed), you
will need to explicitly specify the
profile.

Are you starting Firefox with the actual path to the Firefox browser? If you set Chrome as the target browser you should be able to avoid this.

Related

WebPage works if opened manualy. Returns "Window language could not be determined" if opened via Selenium

I am dealing with a small problem. I am working on automating few tasks in a web application,i can open the webpage,enter the login,click login,BUT then it starts to act strange. If i click on the login manualy it logs in without a problem.
But if i try to do it via selenium (JAVA jdk1.7.0_75,selenium-java-2.53.1,running on IEDriverServer_Win32_3.4.0) the page opens with error An error has occured.
java.lang.NullPointerException. and with "Window language could not be determined "
The page is on the intranet. I guess the application has a problem with the Webdriver (everything works if i try to automate the task using the VBS).
Dont you know any "workaround" for that?
(I can use only IE,because chrome no longer supports NPAPI so the application does not work in chrome)
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("*the webpage*");
driver.findElementByName("userid").sendKeys("*login*");
driver.findElementByName("password").clear();
driver.findElementByName("password").sendKeys("*password*");
driver.findElementByName("ctr").sendKeys("*number*");
driver.findElementByName("menuType").click();
driver.findElementByLinkText("OK").click();
I think the problem is somewhere in the settings,because as i mentioned,if o open the browser manualy and login,it works,no errors and i get into the app.
But the webdriver "browser" has somehow different settings (i think) so it does not work. Problem is,that we have restricted access to the settings of browser,so i cant do much about that.
Thank you very much for any suggestions/answers/tips!!
Kind Regards,
Jerry Woodburn

How to Force Selenium to use Permanent Firefox Profiles with WebDriver?

I'm using Selenium Web Driver API with Java. Whenever I run Web Driver, it automatically creates a tmp Firefox Profile and executes all driver related code relative to the tmp profile.
My issue is not with the extra space this creates as asked in this question: How to stop Selenium from creating temporary Firefox Profiles using Web Driver? and I know I could call driver.quit to clear the resources used by the tmp profile.
Rather, my issue is I want to use the permanent Firefox Profile so that the next time I launch this FF profile I inherit all the cookies and cache of the previous profile. I know I can manually save and add cookies each time but this is tedious.
So, is there any way to force Firefox not to create a tmp profile and launch Firefox as if I was browsing normally using the permanent profile? I just want it to launch as if I was browsing like a normal user.
Thanks
Generally Selenium do not support cross-session cookies.
Most easy way is to use Serialization.
You need to create wrapper class around selenium's cookie and make it serializable. And create class CookiesManager where will be 2 methods: SaveSession() -- to save and RestoreSession() - to restore from serialized file.
Another way is to save some cookies information into some temp cookies file. Like.... Csv or XML.
Sample of this way you can see here: Keep user logged in - save cookies using web driver
but only for c#.
Using specific profile:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("profileToolsQA");
WebDriver driver = new FirefoxDriver(myprofile);
to create some additional profile for firefox you need to run firefox profile manager by the following way: firefox.exe -p

Launch an Application from a Browser

I would like to have a link or button on my web site that launches
vim (an editor) on a specific file (e.g., myfile.txt) on my local machine.
I want to launch C:\Vim\Vim74\gvim.exe on C:\Users\paulco\myfile.txt form any browser.
I want this to work on all (realistically most) browsers.
I actively use Chrome, Opera, FireFox and IE (in that order of preference).
In order for it to work across all of these browsers,
I think the script has to Java-based.
Does anyone know how to do this?
Does anyone have a Java-based script that does this?
Here are some resources I found on the topic.
But either they are IE specific or don't work.
Launch application from a browser
http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx
I have tested the following on Internet Explorer, Chrome, Opera and Firefox.
The browser has to run on a Windows operating system, Linux and Mac require different aproaches.
Solution is to define a protocol handler for a custom protocol.
1) Take this HTML example, it should open the specified text file using notepad.exe:
Open Textfile
2) You need to define the protocol handler in the windows registry, save the following to a file named testing.reg and execute it (double click on it), or enter the values manually using regedit:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\test]
#="URL:Editor test"
"URL Protocol"=hex(2):00,00
[HKEY_CLASSES_ROOT\test\DefaultIcon]
#="\"C:\\Windows\\system32\\notepad.exe\""
[HKEY_CLASSES_ROOT\test\shell]
[HKEY_CLASSES_ROOT\test\shell\open]
[HKEY_CLASSES_ROOT\test\shell\open\command]
#="\"C:\\temp\\editor.bat\" %1"
3) As you can see, I am not calling notepad.exe directly, but a c:\temp\editor.bat batch file. This is because the file-parameter has to be modified. using the %1 as a parameter will pass the complete URL including the test: custom protocol name to the shell. In the script, I use a simple substring pattern to extract the specified file name and call the editor:
REM editor.bat
set param=%1
notepad %param:~5%
That's all!

For Selenium, do I need to start the java server?

$pip install selenium
$sudo apt-get install firefox xvfb
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("http://www.yahoo.com")
This is what I have so far, for Selenium. It seems to work, except it says, "Error: no display specified"
My question is: Do I need to run the selenium jar? It doesn't seem to matter whether I run it or not...
First let me define for you client mode and server mode:
Client mode: where the language
bindings connect to the remote
instance. This is the way that the
FirefoxDriver and the RemoteWebDriver
client normally work.
Server mode:
where the language bindings are
responsible for setting up the
server, which the driver running in
the browser can connect to. The
ChromeDriver works in this way
In the current trunk all of the browsers can run in client mode although you must specify the ChromeDriver.exe path. Server mode can be used to do the same thing. You can set up the jar to run to act as a server for a particular browser. You then connect to that server. If you do this you'll see a Jetty server being set up and it handling requests. If this is not happening then you are not using server mode. As I can see from your code you are currently using client mode so there is no need to run the jar unless you want the extra remote functionality of it.
Running the jar is useful if you want to run tests on a remote machine in which case you run the jar there then connect to it from your local machine. The jar will then deal with launching browsers on the machine it is running on and forwarding actions to it.
I believe in the past with the Selenium RC API, it was necessary to always run the jar but with WebDriver this is not the case.
No, you don't need to run Selenium RC server. You can also use the Webdriver method instead, the preferred method for functional testing, which is a "direct" control of the browser as far as I can tell.
I think the server method "Selenium RC server" is more useful for load testing or multiple user testing, especially in the context of using it with Selenium Grid .

How do I rerun Selenium 2.0 (webdriver) tests on the same browser?

I am trying to use Selenium 2.0 (Webdriver) to implement a series of tests. Before these tests can run, I have to login into the application. Since the application is not my 'own' (testing api-built functionality), each test should not be logging into my application to run.
I would prefer to do the following:
Connect my webdriver tests to my open Firefox browser (already loggedin)
Run my webdriver projects with the same browser.
I understand that Selenium usually assigns a session id to its browsers. However, the current Java implementation of Selenium 2.0 driver does not make use of session id (maybe it does but I don't know where to find it. )
Can someone provide some direction on how to resolve my issue (existing browser and run multiple tests with Selenium 2.0 (java))? Any code provided would also be helpful. Thanks!
Here is what I have learnt:
Selenium 1: As Ioan suggested earlier, use "-firefoxProfileTemplate" when starting up the Selenium RC server and point to the location of your Firefox profile.
Selenium 2: I suppose you can use the Selenium 1 RC server, however, since Selenium 2 uses WebDriver, you can point to the profile information within your code.
File profileDir = new File("/Users/_____/selenium/FFprofile");
FirefoxProfile profile =
new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(
profile);
Notes:
Make sure you run "firefox -profilemanager" to create your initial profile and save your login information.
Allow the browser/website to always store your authentication credentials avoiding "popup"/"login" wwindows, etcs.
Hope this helps somebody who may run into a similar issue: Using the same browser profile in Selenium, etc.

Categories