This is an initial list of FAQs that have been collected for Selenium Core. We encourage people to add to this list and continue feedback on the items listed below.
What is Selenium for?
It is used for functional or system testing web applications. These tests are also sometimes called acceptance, customer, or integration tests. Selenium is not meant for unit testing.
Why can't I get Selenium Core tests to work with Google?
I was trying to write a simple script that does a google search; I get a "Permission Denied" error. Here is my test:
The quick answer is that because of cross-site scripting security built into JavaScript engines in all browsers, you can't edit the content of a web page from another domain. The foreign page will probably load correctly and be visible in the test runner window, but Selenium won't be able to query or edit its contents.
In other words, you can't run selenium on "foo.com" and run a test that edits values and clicks buttons against "bar.com". So, in its current form, you can't "script" google.com because your script isn't currently hosted on google.com. When Selenium and the application you are testing is hosted on the same domain, however, you do not run into the cross-site scripting security feature/limitation.
You can read more about cross-site scripting here: Dev Articles
How can I run my test against a foreign or remote server and get around cross-site scripting security?
There are a few ways around cross-site scripting:
- If possible, deploy Selenium Core, and your tests, on the same web site as the application you're testing.
- You may need to use Selenium IDE
or Selenium Remote Control
to run your tests. See Which Selenium Tool Should I Use?
Selenium IDE is a Firefox extension, (it runs as a "chrome" url) and is therefore not subject to browser security restrictions. Selenium Remote Control provides a client-configured proxy to trick the browser into the thinking the application and the testing tool are coming from the same domain.
- IE Only: Run Selenium as an "HTA" application, or "HTML Application" in Internet Explorer. HTA applications run in the security context of any trusted application on the client, so there is no cross-site scripting limitation. (You can find out more here: MSDN

- Safari Only: Just run Selenium Core directly off of your hard disk as a "file://" URL. HTML files run off the file system aren't restricted by the same-origin policy in Safari 3.x on Mac/Windows.
Why do I get a "Permission Denied" error when accessing my website via HTTPS?
This is actually the same problem as scripting a foreign web-site, described above. "http://mydomain.com" is not the "same origin" as "https://mydomain.com"; using Selenium Core, you can test HTTP or HTTPS, but not both. If you need to test both during a single test, you need to use one of the strategies listed above to test a foreign website.
I can't seem to use Selenium Core to upload a file; when I try to type in the file upload text field, nothing happens!
Unfortunately, this is yet another JavaScript security restriction; JS is not allowed to modify the value of <input type="file"> form fields. You can work around this by running your tests under Selenium IDE or under Selenium RC running in the experimental "*chrome" mode for Firefox, but at present there is no way to do this on any other browser. This is filed as bug SEL-63
, but there may be no way to fix it in Selenium Core.
How do I use Selenium to login to sites that require HTTP basic authentication (where the browser makes a modal dialog asking for credentials)?
Use a username and password in the URL, as described in RFC 1738
:
Note that on Internet Explorer this won't work, since Microsoft has disabled usernames/passwords in URLs
in IE. However, you can add that functionality back in by modifying your registry, as described in the linked KB article. Set an "iexplore.exe" DWORD to 0 in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE.
If you don't want to modify the registry yourself, you can always just use Selenium Remote Control, which automatically sets that that registry key for you as of version 0.9.2.
I don't have access to the server where my AUT (application under test) is deployed, does that matter? IE., is physical deployment of app server and testrunner an issue?
Physical deployment doesn't strictly matter, but if you can't modify your AUT, you do have to somehow either force the browser to disable the same-origin policy or trick the browser into thinking that your tests and your AUT have the same origin.
Selenium isn't working, where are the diagnostics for problem solving?
Look for JavaScript errors. (In IE, check for a warning in your browser status bar; in other browsers you'll want to check the JavaScript console for errors.) Additionally, try opening the logging window before you run your tests; that may reveal problems. You may also want to try using a JavaScript debugger. In Internet Explorer you can configure the MS Script Debugger
; in Mozilla you can configure Firebug
.
Selenium scripts are rather verbose - Is it possible to record these scripts to speed things up?
Yes, use Selenium IDE
This is a firefox plugin, so it requires firefox
, but the results can be replayed using any browser you choose once the script has been created.
Is it possible to run a Selenium test without using a real browser?
No. Selenium is written in JavaScript; it's designed to run in a real browser to test compatibility with a real browser. There are a variety of other tools out there designed to run tests that simulate a browser; we recommend HtmlUnit
or Canoo WebTest
.
Is it possible to use Selenium for multi-user load testing?
Yes, but it requires a LOT of hardware. We recommend you check out BrowserMob, which does load testing with real browsers
and is powered by Selenium.
How can I use a javascript{...} expression as a locator in a Selenium command?
The core documentation states that "All Selenium command parameters can be constructed using both simple variable substitution as well as full javascript". Since locators are important command parameters you might wonder how you can use Javascript to specify a locator e.g. in a 'click' command.
The answer is: Used as a locator, the 'javascript{..}' idiom has to evaluate to a string that represents a valid Selenium locator, e.g. an identifier, css or xpath locator. So if you have a working locator like id=myButton then javascript{["id=","my","Button"].join('')} should work too.
Gotchas:
- If your Javascript block contains multiple statements, the value of the last statement determines the value of the block.
- You can use the 'getEval' command, to debug your Javascript expressions.
How to do it with Selenium
How do I work with a popup window?
In Selenium, you work with one window at a time. To work with a different window, for example one that has popped up as a result of clicking a link, you need to first select that window. In order to select it, you must somehow identify it. Various identification methods can be used (see documentation on the selectWindow command at http://selenium-core.openqa.org/reference.html
); the easiest may be for you to capture the id by recording the popup creation with the Selenium IDE. Something like the following will be recorded:
You probably want to wait for the popup to load before you start interacting with it. Also, when you're done with it, you'll probably want to close it, and reselect the original window. A simple idiom to follow would then be:
waitForPopUp | winId | 30000
selectWindow | winId
...
close
selectWindow
How do I download a file?
Currently it is only possible to do this by configuring Firefox with a profile template, telling it to save a file to a specified location without prompting the user with a file chooser dialog. See here: http://clearspace.openqa.org/message/31350
. There do not appear to be workarounds for other browsers yet.
What you can't do with Selenium
I can't interact with a popup dialog. My test stops in its tracks!
You can, but only if the dialog is an alert or confirmation dialog. Other special dialogs can't be dismissed by javascript, and thus currently cannot be interacted with. These include the "Save File", "Remember this Password" (Firefox), and modal (IE) dialogs. When they appear, Selenium can only wring its hands in despair.
To solve this issue, you may use a workaround (if one exists); otherwise you may have to exclude the test from your automated corpus. For the "Save File" dialog in Firefox, a custom template may be specified when running via the RC that will always cause the file to be downloaded to a specified location, without querying the user (see http://forums.openqa.org/thread.jspa?messageID=31350
). The "Remember this Password" dialog should not appear again after you've chosen to remember it. Currently there is not much that can be done about IE modal dialogs.
How to have a good selenium test suite in terms of organizing stored values and test scripts, since a web application could have hundreds of cases to be tested?