处理javascript弹出窗口

处理javascript弹出窗口

本文介绍了Ruby with Watir:处理javascript弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在watir和javascript弹出窗口方面遇到问题

I have a problem with watir and javascript popup window

这是我的测试脚本

require 'watir'

browser = Watir::Browser.start "/url/"

    browser.link(:text, /Add New Blog/).wait_until_present
    browser.link(:text, /Add New Blog/).click

    // Here is where the javascript window popup
    window = browser.ie.Document.ParentWindow

    browser.window(:title, /Blog/) do
    browser.text_field(:id, /text title of Blog/).set 'Watir'
    browser.select_list(:id, /dropdownlist type/).select ("News")
    browser.button(:value, /Save/).click
    end

问题出在窗口弹出窗口之后,它无法在博客窗口中找到text_field的元素.我也尝试过这个,但是它说=> in 'window': wrong number of arguments (2 for 1) (ArgumentError)

The problem is after window popup shows, it's unable to locate the element of the text_field in window Blog. I also have try this but it says that => in 'window': wrong number of arguments (2 for 1) (ArgumentError)

browser.window(:title => "annoying popup").use do
  browser.button(:id => "close").click
end

有解决方案吗?和顺便说一句我使用红宝石1.9.3.感谢您的帮助.TQ

Any solution? and btw Im using ruby 1.9.3.Appreciate your help.TQ

推荐答案

Watir有两种形式-watir-classic和watir-webdriver.如果可能/方便的话,您应该使用watir-webdriver,因为这是浏览器自动化的未来,并且所有开发重点都将在此发展.

There are two forms of Watir -watir-classic and watir-webdriver.If possible/convenient you should use watir-webdriver because it is the future of browser automation and where all the development focus will be going forward.

如果您使用的是watir-webdriver,则您的代码看起来不错.我从未使用过watir-classic,但似乎它仅支持使用哈希而不是多个参数来初始化窗口.因此,如果您需要使用watir-classic,也许这对您有用:

Your code looks fine if you are using watir-webdriver. I have never used watir-classic, but it appears that it only supports initializing a window with a hash instead of multiple arguments. So maybe this will work for you if you need to use watir-classic:

browser.window(title: /Blog/) { #execute block }

这篇关于Ruby with Watir:处理javascript弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:21