【问题标题】:selenium - how to change current window location without closing the selenium window?selenium - 如何在不关闭 selenium 窗口的情况下更改当前窗口位置?
【发布时间】:2013-06-08 23:17:44
【问题描述】:

我正在使用 seleniumIDE

我希望测试用例根据条件转到另一个位置(注意:条件部分是我使用 javascript 的原因,而使用 if-then 插件现在不是一个选项)。我发现即使javascript{window.location.replace('http://google.com') } 也会关闭我的 seleniumIDE 窗口并用 google 替换它,但不会影响运行测试本身的实际窗口。我已经用1==1 替换了条件本身,即true。简单点

现在我有:

Command  store
Target   javascript{if (1==1) {location="dmstaffing-stage.herokuapp.com/users/sign_out"}}
Value    ignore_me

现在的问题是这会关闭 seleniumIDE 本身并打开一个新窗口。

如何更改正在运行测试的窗口的 URL 位置

使用:

  • this.location.href 给出了一个意外的异常
  • document.location.href 关闭了我的 selenium 窗口,然后打开一个新窗口并访问了注销页面(但原始窗口中的原始页面仍然登录)
  • location.href 也会关闭我的 selenium 窗口并使用注销操作打开一个新窗口

【问题讨论】:

  • 这个操作需要用javascript吗?
  • 是的,这是由于条件问题,因为我不想使用 if-then 插件,因为我会将测试用例导出到 rspec。
  • 你试过window.location.replace("http://stackoverflow.com");
  • 是的,但不幸的是,这在我的 seleniumIDE 窗口上起作用,而不是在运行测试的窗口保持打开并登录。

标签: javascript selenium location href selenium-ide


【解决方案1】:

可以做到,但需要一些魔法。在目标中使用 this.browserbot.openLocation。 例如this.browserbot.openLocation('http://blog.reallysimplethoughts.com/');

Command  storeEval
Target   this.browserbot.openLocation('http://blog.reallysimplethoughts.com/');
Value    ignore_me

您可能想查看Sel Blocks v1.3.1 并在正常打开命令周围使用 if/else。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-29
    • 2021-08-22
    • 1970-01-01
    • 2019-05-16
    • 2021-04-17
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多