【问题标题】:Store absolute URL for selenium test using javascript使用 javascript 存储 selenium 测试的绝对 URL
【发布时间】:2011-09-06 07:59:46
【问题描述】:

我有一个 html 文件,它存储假设存储的 absoluteUrl,其内容是这样的:

<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>

当我尝试用var loc = window.location; 替换window.location 时出现问题,我收到此错误

命令执行失败。请在论坛http://clearspace.openqa.org 中搜索日志窗口中的错误详细信息。错误信息是:eval(match1) is undefined

这是第一个问题。第二个问题是我想使用 javascript 获取绝对路径并尝试存储为 rootUrl 变量。任何解决方案建议都会很方便(如果第一个问题得到解决,我计划尝试类似于 Neville Bonavia 的here 的解决方案,即

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));

}

【问题讨论】:

    标签: javascript html selenium selenium-rc selenium-ide


    【解决方案1】:

    当 Selenium 运行时,this 指的是 Selenium 对象,这意味着您将无法直接访问 windowdocument

    要获得直接访问权限,您需要执行this.browserbot.getUserWindow()。这将返回页面上的window 对象,然后您就可以进行通常的调用了。

    例如

    var window = this.browserbot.getUserWindow();
    return window.location;
    

    【讨论】:

    • 对。这就是我最终使用“this.browserbot.baseUrl”的原因,因为它的路径不会随着测试套件的长度而改变。
    猜你喜欢
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多