使用 Selenium 处理浏览器弹出窗口

发布于 2024-07-04 16:37:04 字数 646 浏览 8 评论 0原文

我们正在针对现有代码库运行 Selenium 回归测试,并且我们的 Web 应用程序中的某些屏幕使用弹出窗口作为中间步骤。

目前我们在测试中使用以下命令:

// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");

...大部分时间都有效。 有时,测试会在 waitForPopUp() 行上失败,并显示“

com.thoughtworks.selenium.SeleniumException: Permission denied

谁能建议一个更好、更可靠的方法?”

此外,我们主要在 IE6 和 7 上运行这些测试。

We are running Selenium regression tests against our existing code base, and certain screens in our web app use pop-ups for intermediate steps.

Currently we use the commands in the test:

// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");

...which works most of the time. Occasionally the test will fail on the waitForPopUp() line with

com.thoughtworks.selenium.SeleniumException: Permission denied

Can anyone suggest a better, more reliable method?

Also, we primarily run these tests on IE6 and 7.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃不饱 2024-07-11 16:37:04

我需要在弹出窗口中选择一个 iframe 并填写表格。
我在使用 selectWindow cmd 时遇到问题,其中 selenium 无法找到我的 iframe,因此我删除了该命令。

这个 Selenese 对我来说效果很好(其中 iframe 标题和 id = account_frame):

<tr>
  <td>click</td>
  <td>//a[@class='item_add']</td>
  <td></td>
</tr>
<tr>
  <td>windowFocus</td>
  <td>account_frame</td>
  <td></td>
</tr>
<tr>
  <td>waitForPopUp</td>
  <td>account_frame</td>
  <td>10000</td>
</tr>

I needed to select an iframe within a popup window and fill out a form.
I had trouble using the selectWindow cmd where selenium couldn't find my iframe, so I removed the command.

This selenese worked well for me (where the iframe title and id = account_frame) :

<tr>
  <td>click</td>
  <td>//a[@class='item_add']</td>
  <td></td>
</tr>
<tr>
  <td>windowFocus</td>
  <td>account_frame</td>
  <td></td>
</tr>
<tr>
  <td>waitForPopUp</td>
  <td>account_frame</td>
  <td>10000</td>
</tr>
唠甜嗑 2024-07-11 16:37:04

尝试在导致问题的调用周围添加一些等待语句。

我以前也遇到过同样的错误,我能够可靠解决这些错误的唯一方法是调用 System.Threading.Thread.Sleep(5000)..

Try adding some wait statements around the calls that are causing you issues.

I've had the same errors before and the only way I was able to reliably resolve them was by making calls to System.Threading.Thread.Sleep(5000)..

不忘初心 2024-07-11 16:37:04

如果您在 *iehta 模式下运行,那么您将会在这里或那里遇到一些故障。 我们在工作中运行 Selenium,并且 IE 和 AJAX 似乎存在很多问题。

然而,听起来您遇到的问题是 Selenium 试图在完全加载之前访问另一个窗口中的组件。 我不确定您的默认超时范围设置为多少,但您可能需要尝试将其增加到 60 (60000ms) 秒左右以解决该问题。

除此之外,我建议在 Firefox 中运行测试(使用 *chrome),因为它会产生更可靠的结果,但有时由于业务需求,这是不可能的。

If you are running in *iehta mode then you are going to run into some glitches here and there. We run Selenium at my job and there seem to be lots of issues with IE and AJAX.

However, it sounds like the issue you are running into is one where Selenium is trying to access a component in another window before it completely loads up. I am not sure what your default timeout range is set to, but you may want to try increasing it to 60 (60000ms) seconds or so to get past the issue.

Other than that I would suggest running your tests in Firefox (using *chrome) as it produces much more reliable results, but sometimes it is simply not possible due to business requirements.

往事风中埋 2024-07-11 16:37:04

有用!! 只是为了让那些喜欢 Selenese 的人更容易。

这对我使用 IE7(正常模式)有用。

真是太麻烦了。 感谢天空中的意大利面怪物,否则我不可能在 IE 中运行它。

<tr>
    <td>getEval</td>
    <td>selenium.browserbot.getCurrentWindow().open('', 'windowName');</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>buttonName</td>
    <td></td>
</tr>
<tr>
    <td>windowFocus</td>
    <td>windowName</td>
    <td></td>
</tr>
<tr>
    <td>waitForPopUp</td>
    <td>windowName</td>
    <td>3000</td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>windowName</td>
    <td></td>
</tr>

It works!! Just to make it easier for the folks who prefer selenese.

This worked for me using IE7(normal mode).

What a freaking hassle. Thank the spaghetti monster in the sky for SO or there is no way I would have got this working in IE.

<tr>
    <td>getEval</td>
    <td>selenium.browserbot.getCurrentWindow().open('', 'windowName');</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>buttonName</td>
    <td></td>
</tr>
<tr>
    <td>windowFocus</td>
    <td>windowName</td>
    <td></td>
</tr>
<tr>
    <td>waitForPopUp</td>
    <td>windowName</td>
    <td>3000</td>
</tr>
<tr>
    <td>selectWindow</td>
    <td>windowName</td>
    <td></td>
</tr>
岛歌少女 2024-07-11 16:37:04

我刚刚尝试添加另一个 selenium 函数 windowFocus()

// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().windowFocus("enquiryPopup");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");

当我在本地运行它时测试成功,但仅限于所有这些方法调用 - create/focus/wait/select。

我即将让构建服务器运行所有测试,如果也成功,我将用它创建一个库函数......!

I just trialled adding another selenium function, windowFocus():

// force new window to open at this point - so we can select it later
selenium().getEval("this.browserbot.getCurrentWindow().open('', 'enquiryPopup')");
selenium().click("//input[@value='Submit']");
selenium().windowFocus("enquiryPopup");
selenium().waitForPopUp("enquiryPopup", getWaitTime());
selenium().selectWindow("enquiryPopup");

The test succeeded when I ran it locally, but only with all those method calls - create/focus/wait/select.

I'm about to let the build server run all the tests, and if that succeeds too, I'll be making a library function out of it...!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文