Selenium and the Permission denied to get property Location.href problem
I came across a strange behaviour of Selenium and wanted to share my pain with someone really. But first couple of words of introduction. I use Selenium in my current webapp project which I am working on. The application uses quite a lot of javascript (Dojo framework mostly) which can be tested using D.O.H. framework but the Selenium is giving us the final sanity checks, acts as integration test framework and may be used by product owner in an agile environment to drive acceptance on user stories via automated acceptance tests.
Selenium is an excellent package. I really love it. Just to mention integration with various browsers, Selenium IDE, support for integration with build (Selenese ant task) and really easy way of creating and storing the tests as HTML. It is a framework which cannot be ignored by anyone working on webinterfaces.
There is previously mentioned selenese ant task which helps with integration of the Selenium tests and an ant build. You can grab the jar from the Selenium RC distribution.
However as most of the things around us it is not a perfect software. Anyone had the famous “Permission denied to get property Location.href”? Cross domain scripting issues?
In my case I figure out two reasons for above problem and I wanted to share it:
Problem 1:
Let’s look at the following selenium command:
- open
- http://host/some/url
Looks good, doesn’t it? So it might work, but it can as well break on another box with the “Permission denied to get property” and some other scary warnings. The solution in this case was simply to remove the host definition from url leaving just:
- open
- /some/url
Problem 2:
One of the pages I was testing had redirection in case of the authorization violation. So esentially after single HTTP request the browser was receiving single response with redirection and then performed another request to the URL defined in the redirection. Selenium couldn’t handle that correctly. But again, it wasn’t deterministic, it could work on one box but fail on another. Timing issues etc. Hate that. Neither of the combinations worked in consistent way: openAndWait, open + pause.
The solution in this case required change in the webapp to remove usage of the redirection (which I believe was an ugly way of dealing with the problem anyway).
Hope it will help someone with similar issues. If you know another tricks or something to avoid when using Selenium please contact me or leave a comment here.
Popularity: 65% [?]

znachor said,
May 25, 2008 @ 2:14 pm
Another hint: Nathan let me know that compressing all java scripts to one file using for instance Dojo ShrinkSafe (http://dojotoolkit.org/docs/shrinksafe) and including that one file from your local server will result in less cross domain scripting issues. Worth trying.
Ariz Jacinto said,
June 16, 2008 @ 11:00 pm
in the case of the redirection problem (@ #2), you have to assert all the location that the web app will go to in order for the test to work
e.g.
$this->assertLocationEquals(”http://domain/path1/”);
$this->waitForPageToLoad(1000);
$this->assertLocationEquals(”http://domain/path2/”);
…
Rob Dupuis said,
July 1, 2008 @ 9:23 pm
I just had this problem with selenium rc.
My session was started using an ip address: http://192.168.1.4:3000
It turned out that some of my app was rendering some links as http://localhost:3000/blah/blah instead of http://192.168.1.4:3000/blahblah
The result of this was that my calls to waitForPageToLoad (or wait_for_page_to_load in ruby) ended up spitting out ‘Permission denied to get property Location.href’
Taken me hours to track down.
Fabio Brandão - Blog » Blog Archive » Selenium - Permission denied to get property Location.href said,
July 23, 2008 @ 2:36 pm
[…] http://www.woloszyn.org/2008/04/22/selenium-and-the-permission-denied-to-get-property-locationhref-p… […]