Watir 帮助:click-no-wait 和 execute_script 没有按预期工作 [英] Watir Help: click-no-wait and execute_script not working as expected

查看:28
本文介绍了Watir 帮助:click-no-wait 和 execute_script 没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ruby​​ 的 Watir gem,我试图单击一个按钮打开一个 javascript 弹出窗口,然后在弹出窗口上单击确定",但我似乎无法做到这一点.该按钮位于框架中的框架中.我已经广泛搜索并阅读了 Watir wiki entry 关于 javascript 弹出窗口但什么也没有作品.
我认为这是因为 execute_script 和 click_no_wait 没有按预期工作.
例如,以下命令:

Using ruby's Watir gem, I'm trying to click a button that opens a javascript popup, then click 'ok' on the popup and I can't seem to do that. The button is in a frame in a frame. I have searched extensively and read the Watir wiki entry about javascript popups but nothing works.
I think this is because execute_script and click_no_wait are not working as expected.
For example, the following commands:

    @browser.execute_script('window.alert = function() {}')
    @browser.execute_script('alert("hello")')

创建一个显示你好"的 javascript 弹出窗口,而不是不做任何事情的预期行为.
命令:

create a javascript popup that says "hello" instead of the expected behavior of not doing anything.
The command:

    @browser.button(:value, 'Submit').click

单击创建 javascript 弹出窗口的按钮.然后脚本挂起,直到我在弹出窗口中手动单击确定".
命令:

Clicks the button which creates a javascript popup. The script then hangs until I manually click 'ok' on the popup.
The command:

    @browser.button(:value, 'Submit').click_no_wait

不点击按钮(或者确实点击了按钮并且不触发 onclick 事件).
我也试过:

Does not click the button (or it does click the button and doesn't trigger the onclick event).
I have also tried:

    Timeout::timeout(1) { @browser.button(:value, 'Submit').click }

    Thread.new { @browser.button(:value, 'Submit').click }

但是 Timeout 永远不会抛出异常,导致 ruby​​ 挂起,直到我在弹出窗口上手动单击确定",当我在新线程中运行它时,Watir 不会单击.

But Timeout never throws an exception, causing ruby to hang until I manually click 'ok' on the popup, and Watir doesn't click when I run it in a new thread.

有人可以提供帮助或提供解决方案吗?

问题是在@browser.button.click 之后,脚本会挂起,直到弹出窗口关闭.@browser.alert.ok 成功关闭弹窗,但是点击按钮后脚本无法执行@browser.alert.ok,因为它会挂起直到弹窗关闭.这个catch-22应该通过click_no_wait解决,但是click_no_wait没有点击.

Would anyone be able to help or offer a solution?

The problem is that after @browser.button.click, the script hangs until the popup closes. @browser.alert.ok successfully closes the popup, but the script cannot execute @browser.alert.ok after the button is clicked because it hangs until the popup is closed. This catch-22 is supposed to be solved by click_no_wait, but click_no_wait is not clicking.

系统信息:
Windows 7 企业版 64 位
浏览器版本 9.0.12
watir-4.0.2-x86-mingw32
红宝石 1.9.3p286 (2012-10-12) [i386-mingw32]

System information:
Windows 7 Enterprise 64 Bit
Internet Explorer Version 9.0.12
watir-4.0.2-x86-mingw32
ruby 1.9.3p286 (2012-10-12) [i386-mingw32]

推荐答案

有一个警报 api (watir-classicwatir-webdriver) 可以用来与 javascript 弹出窗口交互.

There is an alert api (watir-classic and watir-webdriver) that you can use to interact with the javascript popup.

尝试关闭弹出窗口:

@browser.alert.ok

更新 - 解决方法:

这似乎是对框架中的元素使用 Element#click_no_wait 的错误.我已经更新了问题 45 并将尝试提交补丁.

This appears to be a bug with using Element#click_no_wait for elements in a frame. I have updated Issue 45 and will try to submit a patch.

与此同时,在脚本开头添加以下猴子补丁应该可以解决问题(即 click_no_wait 不应等待):

In the mean time, adding the following monkey patch at the start of your script should solve the issue (ie the click_no_wait should not wait):

require 'watir-classic'

Watir::IE.new(true)
module Watir
    class Frame
        def attach_command
            tag_name = @specifiers[:tag_name].join("' << '")
            @container.page_container.attach_command + ".frame(:tag_name => Array.new << '#{tag_name}', :unique_number => #{unique_number})"
        end
    end
end

这篇关于Watir 帮助:click-no-wait 和 execute_script 没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆