【问题标题】:Watir webdriver_unable to click Cancel Target button on popup windowWatir webdriver_无法单击弹出窗口上的取消目标按钮
【发布时间】:2015-03-13 20:54:49
【问题描述】:

我对 Watir 非常陌生,正在尝试测试一个弹出窗口,但无法让我的脚本单击“取消目标”按钮。运行脚本时,出现错误:element not visible (Selenium::WebDriver::Error::ElementNotVisibleError。这是我正在使用的脚本:

browser.div(:class => "modal-footer").button(:class => "btn btn-danger").click

下面是代码:

<div class="modal hide fade" id="target_modal" data-bind="with: target">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 data-bind="text: BusinessName"></h3>
    </div>

    <div class="modal-body">
        <div class="row">
            <div class="span3">
                <label for="FirstName">First Name</label><input id="FirstName" type="text" data-bind="value:FirstName" />
                <label for="LastName">Last Name</label><input id="LastName" type="text" data-bind="value: LastName" />
                <label for="Email">Email</label><input id="Email" type="text" data-bind="value: Email" />
            </div>
        </div>
    </div>

    <div class="modal-footer">
        <button class="btn btn-primary" data-bind="click: saveTarget">
            <i class="icon-white icon-ok"></i>
            Save Target
        </button>

        <button class="btn btn-danger" data-dismiss="modal">
            <i class="icon-white icon-remove"></i>
            Cancel Target
        </button>
    </div>
</div>

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: webdriver watir


    【解决方案1】:

    我假设这个弹出窗口是页面的一部分(即只是一个覆盖页面其余部分的 div 标签),而不是一个新的浏览器窗口弹出窗口。

    我的猜测是 Watir 试图在弹出窗口完成显示之前单击按钮。明确告诉 Watir 等待按钮可能会解决问题:

    cancel_button = browser.div(:class => "modal-footer").button(:class => "btn btn-danger")
    cancel_button.when_present.click
    

    【讨论】:

    • 感谢您这么快回来。尝试了上述和脚本超时: C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.4/lib/watir-webdriver/wa it.rb:30:in @ 987654322@method_missing' 来自 targetcustomer.rb:29:in `
      '
    • 想到了 2 种可能性。 (1) 没有显示弹出窗口。上面的代码假定您已经触发了要显示的弹出窗口。如果您观看脚本运行,您是否看到要单击的按钮? (2) 这些&lt;div class="modal-footer"&gt; 元素有多个。 Watir 选择 html 中的第一个,而不是第一个可见的。如果你添加一个puts browser.divs(:class =&gt; "modal-footer").collect(&amp;:visible?),你会得到什么?
    • (1) 脚本运行时我确实看到了按钮。 (2) 在cmd窗口中,添加puts browser.divs(:class=> "modal-footer").collect(&:visible?)时返回3'false'
    • 好吧,我猜你想要的取消按钮不在第一个 modal-footer div 元素中。我们需要限定定位器以查看正确的模态页脚。 target_modal id 是唯一的吗?例如,browser.elements(:id =&gt; 'target_modal').length 有什么作用?
    • 我让它工作了。你的第一个答案让我思考,这很有效:cancel = browser.div(:id => "target_modal") cancel.div(:class=> "modal-footer").button(:class=> "btn btn-danger ").i(:class=> "icon-white icon-remove").click
    【解决方案2】:

    我让它工作了。 Justin Ko 的第一个答案让我思考,这很有效:

    cancel = browser.div(:id => "target_modal") 
    cancel.div(:class => "modal-footer").button(:class => "btn btn-danger").i(:class => "icon-white icon-remove").click
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多