Over a million developers have joined DZone.

Selenium Mojo : "Access Is Denied"


At work we maintain a suite of Selenium RC tests that numbers 150 strong. Before each of our releases we execute the entire suite multiple times in multiple environments against Internet Explorer (IE) 7 and 8.

Selenium scales surprisingly well in most respects but one issue stymied our team early on.  Right as the selenium client would start up and launch the browser it would hang on this popup:


Access is denied? Line 857? RemoteRunner.hta? Huh?

As you probably know Selenium is unable to control a popup, like the one above, that originates from the browser. When you run selenium tests you often have to configure your browser to supress many different kinds of popups. Unfortunately IE offered no way to disable this particular type.

This popup would happen perhaps 1 out of 100 test runs. It would interrupt the test run and force us to kill the selenium process which would lose the test results for that run. It originated in the selenium codebase so there was no way to trap the error. Eh gads...

We run our tests with singleBrowserMode set to false (due to a bug with Selenium not handling cookies properly with HTTPS.) This causes selenium to launch two windows: a "master" window that runs the test code and a "slave" window that browses to your application.

Long story short our team tracked this error down deep into the selenium JavaScript code base (htmlutils.js) to a function it calls to create the "slave" window:

function openSeparateApplicationWindow(url, suppressMozillaWarning) {
// resize the Selenium window itself
window.resizeTo(1200, 500);
window.moveTo(window.screenX, 0);

var appWindow = window.open(url + '?start=true', 'seleniummainapp_window');
if (appWindow == null) {
var errorMessage = "Couldn't open app window; is the pop-up blocker enabled?"
throw new Error("Couldn't open app window; is the pop-up blocker enabled?");
try {
var windowHeight = 500;
if (window.outerHeight) {
windowHeight = window.outerHeight;
} else if (document.documentElement && document.documentElement.offsetHeight) {
windowHeight = document.documentElement.offsetHeight;

if (window.screenLeft && !window.screenX) window.screenX = window.screenLeft;
if (window.screenTop && !window.screenY) window.screenY = window.screenTop;

appWindow.resizeTo(1200, screen.availHeight - windowHeight - 60);
appWindow.moveTo(window.screenX, window.screenY + windowHeight + 25);
} catch (e) {
LOG.error("Couldn't resize app window");

if (!suppressMozillaWarning && window.document.readyState == null && !seenReadyStateWarning) {
alert("Beware! Mozilla bug 300992 means that we can't always reliably detect when a new page has loaded. Install the Selenium IDE extension or the readyState extension available from selenium.openqa.org to make page load detection more reliable.");
seenReadyStateWarning = true;

return appWindow;
Aha! Notice that when they try to resize and move the "appWindow" they put a try/catch block around the resizeTo and moveTo function calls. These methods can throw an access is denied error if the browser security settings are violated or if the page is not fully loaded. But in the first two lines where "window" is resized and moved there is no try/catch!

The root cause was that there was a race condition in which the "master" window would not always be fully loaded before this code was executed.

The fix I did was to unzip the selenium server jar file, add a try/catch around the first two lines of the method above, and then zip it up again.

Hopefully the upcoming release of Selenium 2.0 will avoid this problem, but if you are running 1.0.1 or below this may be a useful workaround.

Published at DZone with permission of Scott Leberknight, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}