Store absolute URL for selenium test using javascript
I have a html file which stores which suppose to store the absoluteUrl whose content is this :
<html>
<head><title>Root URL variable</title></head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Root URL variable</td></tr>
</thead><tbody>
<tr>
<td>store</td>
<td>javascript{window.location;}</td>
<td>rootUrl</td>
</tr>
</tbody></table>
</body>
</html>
The problem arises when I try to replace window.location
with var loc = window.location;
I a开发者_开发技巧m getting this error
Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: eval(match1) is undefined
That is the first issue. Second issue is that I would like to get the absolute path using javascript and try to store as the rootUrl variable. Any solution suggestions will be handy(If the first problem is solved I am planning to try solution similar to the one here by Neville Bonavia i.e.
function getAbsolutePath() {
var loc = window.location;
var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}
When Selenium is running this
refers to the Selenium object which means that you won't have direct access to window
or document
.
To get direct access you will need to do this.browserbot.getUserWindow()
. That returns you the window
object on the page and then you can make your usual calls.
e.g.
var window = this.browserbot.getUserWindow();
return window.location;
精彩评论