Dashboard > Selenium Remote Control > Home > Selenium RC FAQ
Selenium Remote Control Log In View a printable version of the current page.
Selenium RC FAQ
Added by Patrick Lightbody, last edited by Nelson Sproul on Apr 02, 2008  (view change)
Labels: 
(None)

Where should I go if I have questions about Selenium RC that aren't answered in this FAQ?

Try our user forums.

What is Selenium RC?

Selenium RC (aka SRC) is a server that allows you to launch browser sessions and run Selenium tests in those browsers. Conceptually, the server exposes two main interfaces to the outside. One is for controlling the browser, the other is to receive commands that instruct it what to do. This way, independent processes (think: test programs) can instruct SRC which action to perform on the browser.

In order to achieve this, the SRC server acts as an intercepting proxy for the browser. With the initial URL at startup, the browser obtains the Selenium engine (Selenium Core and other tools). Subsequent calls to open URLs are passed through SRC which proxies these requests. This way the AUT is received and can be controlled by Selenium in the browser. Further commands do the usual Selenium stuff, like asserting page elements, clicking links and filling forms. All these commands are received by SRC through its command interface from independent processes. There is a variety of language bindings available (Java, Python, Ruby, ...) to write programs to this end.

Additionally to the image provided in the Selenium RC tutorial there is a (slightly more accessible) overview diagram of the Selenium RC architecture in the attachment section of this article (selenium-rc-overview.pdf). If you want to get started with Selenium RC, do read the tutorial.

When first starting the server, I get this error message: "(Unsupported major.minor version 49.0)"

This is Java's extremely unhelpful error message telling you that you're not using the correct version of Java. The Selenium Server requires Java 1.5 or higher; this typically happens when you use Java 1.4 instead of 1.5. Try running this from the command line:

java -version

You should see a brief message telling you what version of Java is installed, like this:

java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode)

If you see a lower version number instead, you may need to install a newer version of the JRE, or you may need to add it to your PATH environment variable.

During the tutorial, I get a 404 error when running the getNewBrowserSession command!

First, finish reading the tutorial. Make sure you read the section about the "Same Origin Policy" carefully.

If you're getting a 404 error while attempting to open a page on "http://www.google.com/selenium-server/", then it must be because the Selenium Server was not correctly configured as a proxy. Remember, that directory doesn't really exist on google.com; it only appears to exist when the proxy is properly configured.

Now the question to ask is: why isn't my proxy properly configured? There are a number of possible reasons, depending on which way you launched your browser: with *firefox, *iexplore, *opera, or *custom.

  • *iexplore: If you launched your browser using *iexplore, there are a number of likely possibilities.
    Selenium Server attempts to configure the global proxy settings in your Internet Options control panel; we need to make sure that those are correctly configured when Selenium Server launches the browser. Try looking at your Internet Options control panel. Click on the "Connections" tab and click on "LAN Settings".
    • If you have checked "Automatically detect settings" (the top check box), you'll need to uncheck it before using Selenium RC. This is filed as bug SRC-22.
      If you need to use a proxy to access the application you want to test, you'll need to start Selenium Server with "-Dhttp.proxyHost"; see the command line options for more details.
    • Also note, as this Control Panel states, that "these settings will not apply to dial-up or VPN connections". If you're on a dial-up or VPN connection, Selenium RC cannot automatically configure the IE proxy... in fact, as far as we know, there's no standard way to configure your proxy at all, even manually! (This is filed as bug SRC-21, but it may not be possible to fix it.) As a workaround, you may be able to use the experimental *iehta browser launcher instead.
    • As a last resort, you may try configuring your proxy manually and then launching your browser with *custom, or with our experimental *iehta browser launcher.
  • *custom: When using *custom, it's up to you to configure the proxy correctly (manually). If you forgot to do this, or if you configured the proxy incorrectly, you'll get a 404 error. Double-check that you've configured your proxy settings correctly. Note that in some browsers it's very easy to make a mistake and change the wrong settings, thinking that you've configured your proxy, when you've really had no effect at all.

    One way to tell whether you've configured your proxy correctly is to attempt to intentionally configure your browser incorrectly. Try configuring your browser to use the wrong proxy server hostname, or the wrong port. If you've successfully configured your browser's proxy settings incorrectly, your browser will be unable to connect to the Internet, which is one way to make sure you're adjusting the relevant settings.

    For example, you might try configuring your browser to use the proxy server "asdflkjdasf" on port "1234". Then try connecting to google.com in the ordinary way, and doing a search. If you connect successfully to google.com, then you must not have really changed your proxy settings at all! You might also try turning your Selenium Server off while using the correct settings (localhost on port 4444). You should not be able to connect to Google if your proxy is disabled. If it seems like you can, then you know you've almost certainly made a mistake.

    Note that this problem can be especially troublesome on Internet Explorer, which can sometimes ignore whatever proxy settings are configured, even manually! (This normally happens when you're using a dial-up Internet connection, or if you're using a VPN.) In that case, you may not be able to configure your proxy at all. As a workaround, you may be able to use the experimental *iehta browser launcher instead.
  • SSL/HTTPS: If you attempt to start a browser session on an HTTPS URL, we will try to use our proxy to intercept these encrypted instructions. See the section on HTTPS in the tutorial. This may cause your browser to spawn a pop-up warning you that someone may be intercepting your secure transaction; in this case, that is actually happening. Our proxy is forging SSL credentials and trying to make your browser accept them. (We hope to one day to be able to automatically configure browsers not to present these warnings.) In the meantime, if our built-in SSL support doesn't work for you, you'll have to use one of our experimental browser launchers to test sites that require HTTPS support.
  • others (*firefox, *opera): For the others, we automatically hard-code the proxy for you, and don't know of any known issues with this functionality. If you're encountering 404 errors in the tutorial while using these browser launchers, post them to our user forums... they might be bugs!

During the tutorial, I can't access Google when running the "open" command!

First, finish reading the tutorial. Make sure you read the section about the "Same Origin Policy" carefully.

There's a couple of possible reasons this might be happening:

  • This might be a simple issue where you've mistyped the commands. Make sure you type the commands exactly as they appear in the tutorial.
  • Selenium RC automatically configures the browser to use the Selenium Server as a proxy. But if you need to use another proxy to access the Internet, then you may not be able to access Google while using the Selenium Server as a proxy. (The Selenium Server will not automatically use your proxy; it will attempt to contact Google directly.)

    If you need to use a proxy to access the application you want to test, you'll need to start Selenium Server with "-Dhttp.proxyHost"; see the command line options for more details.

Why am I getting a permission denied error?

This is covered in some detail in the tutorial. Make sure you read the section about the "Same Origin Policy" carefully.

The most common reason for this error is that your session is attempting to violate the same-origin policy by crossing domain boundaries (e.g., accesses a page from http://domain1 and then accesses a page from http://domain2) or switching protocols (moving from http://domainX to https://domainX).

This error can also sometimes occur when JavaScript attempts to look at objects which are not yet available (before the page has completely loaded), or tries to look at objects which are no longer available (after the page has started to be unloaded). This kind of pitfall is most typically encountered with AJAXy pages which are working with sections of a page or subframes that load and/or reload independently of the larger page. For this category of problem, it is not unusual that the error is intermittent. Often it is impossible to reproduce the problem with a debugger running because the trouble stems from race conditions which settle down when the debugger's overhead is added to the system.

How can I fix a permission denied error?

Try using one of our experimental browser launchers.

Selenium Server launches the browser in just one particular configuration (pop-ups blocked, etc.). I need to test running the browser in a different configuration. How do I do that?

Normally Selenium RC automatically configures your browser, but if you launch your browser using "*custom" as your browser launcher, you can force Selenium RC to launch the browser as-is, without changing your configuration. (Note that this is also the way you launch other browsers that Selenium RC doesn't yet explicitly support.)

For example, you can launch Firefox with a custom configuration like this:

cmd=getNewBrowserSession&1=*custom c:\Program Files\Mozilla Firefox\firefox.exe&2=http://www.google.com

Note that when we launch the browser in this way, you'll have to manually configure your browser to use the Selenium Server as a proxy. (Normally this just means opening your browser preferences and specifying "localhost:4444" as an HTTP proxy, but instructions for this can differ radically from browser to browser, so consult your browser's documentation for details.)

Beware that Mozilla browsers can be a little fidgety about how they start and stop. You may need to set the MOZ_NO_REMOTE environment variable to make Mozilla browsers behave a little more predictably. Unix users should avoid launching your browser using a shell script; always prefer to use the binary executable (e.g. firefox-bin) directly.

If you attempt to launch a *custom browser but don't configure the proxy correctly, you won't be able to get through even a simple Google test, because you'll get a 404 (File not found) error trying to access http://www.google.com/selenium-server/. Remember, that directory doesn't really exist on Google.com; it only appears to exist when the proxy is properly configured. If you get this error, double-check that you've configured your proxy settings correctly. Note that in some browsers it's very easy to make a mistake and change the wrong settings, thinking that you've configured your proxy, when you've really had no effect at all.

One way to tell whether you've configured your proxy correctly is to attempt to intentionally configure your browser incorrectly. Try configuring your browser to use the wrong proxy server hostname, or the wrong port. If you've successfully configured your browser's proxy settings incorrectly, your browser will be unable to connect to the Internet, which is one way to make sure you're adjusting the relevant settings.

For example, you might try configuring your browser to use the proxy server "asdflkjdasf" on port "1234". Then try connecting to google.com in the ordinary way, and doing a search. If you connect successfully to google.com, then you must not have really changed your proxy settings at all! You might also try turning your Selenium Server off while using the correct settings (localhost on port 4444). You should not be able to connect to Google if your proxy is disabled. If it seems like you can, then you know you've almost certainly made a mistake.

Note that this problem can be especially troublesome on Internet Explorer, which can sometimes ignore whatever proxy settings are configured, even manually! (This normally happens when you're using a dial-up Internet connection, or if you're using a VPN). In that case, you may not be able to configure your proxy at all. As a workaround, you may be able to use the experimental *iehta browser launcher instead.

I'm getting a pop-up during my test and my test freezes. What can I do about it?

There's actually several different kinds of "pop-ups" that you can get during a Selenium test; each of them need to be addressed differently.

  • HTTP basic authentication dialogs: These dialogs prompt you for a username/password to login to the site. To login to a site that requires HTTP basic authentication, ose a username and password in the URL, as described in RFC 1738, like this: open("http://myusername:myuserpassword@myexample.com/blah/blah/blah").
  • SSL certificate warnings: Selenium RC automatically attempts to spoof SSL certificates when it is enabled as a proxy; see more details about this in the tutorial section on HTTPS. If your browser is configured correctly, you should never see SSL certificate warnings, but you may need to configure your browser to trust our dangerous "CyberVillains" SSL certificate authority. (The tutorial explains how to do this.)
  • modal JavaScript alert/confirmation/prompt dialogs: Selenium tries to conceal those dialogs from you (by replacing window.alert, window.confirm and window.prompt) so they won't stop the execution of your page. If you're actually seeing an alert pop-up, it's probably because it fired during the page load process, which is usually too early for us to protect the page.

    We ideally suggest that you modify your application to avoid creating alerts before window.onload. If that's impossible, you may have luck using our experimental proxy injection mode which protects the page from alerts earlier than regular mode.

On Linux, why isn't my Firefox browser session closing?

On Unix/Linux we need to invoke "firefox-bin" directly, so make sure <i>that</i> executable is on the path. If we're forced to execute Firefox through a shell script, when it comes time to kill the browser Selenium RC will kill the shell script, leaving the browser running.

If necessary, you can specify the path to firefox-bin directly, like this:

cmd=getNewBrowserSession&1=*firefox /usr/local/firefox/firefox-bin&2=http://www.google.com

Where can I find the latest nightly build?

Sometimes we have bug fixes that are in un-released code. You can find the latest SNAPSHOT version at http://maven.openqa.org/org/openqa/selenium/selenium-remote-control/.

How can I do away with the great fragility that using complex xpath expressions brings to my test?

If the elements in your HTML that are directly accessed (button, table, label, etc) have element IDs, then you can reliably retrieve all elements without ever resorting to xpath.

These element IDs should be explicitly created by the application or by a human being; there should be no reliance on a UI framework to create element ids. Otherwise you will tend to end up with non-specific element IDs, i.e. id_147. This sort of non-descriptive element ID tends to cause two problems: first, each time the application is deployed, different element ids could be generated. Second, a non-specific element id makes it hard for automation testers to keep track of and determine which element ids are required for testing.

You might consider trying the UI-Element extension.

Is it ok to load a custom pop-up as the parent page is loading (i.e., before the parent page's javascript window.onload() function runs?

No. Selenium relies on interceptors to determine window names as they are being loaded. These interceptors work best in catching new windows if the windows are loaded AFTER the onload() function. Selenium may not recognize windows loaded before the onload function.

How can I pause until an element is created (e.g., in an AJAX app where the page has already loaded, but a partial in-place refresh will create an element)?

Don't use polling or waitForPage to wait for a condition; instead use Wait
You can make your test faster and more robust by waiting for the particular condition that you require as shown in the following example:

new Wait() {
    public boolean until() {
        return selenium.isElementPresent("foo");
    }
}.wait("element foo not found");

This code snippet will pause until the element "foo" exists, after which it will immediately resume execution.

How can I evaluate (eval) javascript expression on a page being tested?

Use

selenium.getEval(expression);
or
selenium.runScript(script);

How can I drive my tests based on some data source, e.g., an external spreadsheet?

If you're using Java, TestNG will help you solve this problem more effectively than junit; see http://www.testng.org for details. Dan Fabulich has written a simple example of a test driven by a data provider; I've attached that code as DataProviderExample.java. (Don't bother him for support with this. But feel free to submit fixes.)

I've also attached an example of how to read from an Excel spreadsheet from Java.

Firefox 2.0 doesn't start up with Selenium RC 0.9.0!

There's a bug (SRC-216) that prevents Firefox 2.0.0.1 or later from starting up in Selenium RC 0.9.0. Use 0.9.2 instead.

Firefox *chrome doesn't work with custom profile?

Check your Firefox profile folder -> prefs.js -> user_pref("browser.startup.page", 0);
Comment this line like this: "//user_pref("browser.startup.page", 0);" and try again.

Why does the selenium server need a proxy?

The motivation here is to conform to JavaScript's same-domain rule (see http://www.google.com/search?hl=en&q=same+origin+rule+JavaScript&btnG=Search for details). We want the browser to be able to talk to both the web site being tested, and also to the selenium server itself. This presents a problem, since they will not normally be from the same domain. The solution is to have all communication go through the selenium server running as a proxy, where communication from the browser-side selenium test management harness is intercepted and swallowed up by the selenium server, and other queries are forwarded out to the web site being tested.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators