【问题标题】:watir-classic 3.7.0 click on unsupported tagwatir-classic 3.7.0 点击不支持的标签
【发布时间】:2014-02-10 11:09:01
【问题描述】:

我正在尝试单击不支持的带有 watir classic 3.7.0 的标签。一般来说,看起来我可以找到带有如下行的标签:

browser.td(:id, 'Proceed').element(:tag_name => 'FONT')

和

browser.td(:id, 'Proceed').element(:tag_name => 'FONT').class

返回 watir::HTMLElement,但我找不到任何文档(仅 Element)

使用

browser.td(:id, 'Proceed').element(:tag_name => 'FONT').methods

表明它有方法点击,但正在运行

browser.td(:id, 'Proceed').element(:tag_name => 'FONT').click

结果:

undefined method 'each' for "FONT":String (NoMethodError)

我已经尝试为字体标签制作一个模块:

module Watir
    module Container
        def font(*args)
            FONT.new(self, extract_selector(args).merge(:tag_merge => "font"))
        end

        def fonts(*args)
            GCollection.new(self, extract_selector(args).merge(:tag_merge => "font"))
        end
    end

    class FONT < Element
    end

    class GCollection < ElementCollection
        def element_class
            FONT
        end
    end
end

但这会引发错误,

undefined_method 'extract_selector' for #<Watir::TableRow:0x2835378> (NoMethodError)

如何点击这个不受支持的标签?

【问题讨论】:

  • 为什么你只限于 Watir-classic?为什么不升级?
  • 来自 watir.com,我相信我刚刚做了 gem install watir --no-rdoc --no-ri - 那是最新版本。有更好的版本吗? ...它会解决这个问题吗?
  • 查看 Justin 的回答,了解适合您的解决方案。另外,我建议考虑迁移到 watir-webdriver。

标签: html ruby internet-explorer automated-tests watir


【解决方案1】:

您好像遇到了Issue 62。

解决方案 1 - 升级 Watir-Classic

此错误已在最新版本的 watir-classic 中修复。请注意,您需要升级 watir-classic gem(不仅仅是 watir gem):

gem install watir-classic

解决方案 2 - 使用数组

如果不能升级到最新版本,您可以将 :tag_name 值设为数组:

browser.td(:id, 'Proceed').element(:tag_name => ['FONT']).click

解决方案 3 - 使用字体方法

我刚刚仔细检查了font 元素实际上是supported。所以我会说更好的解决方案,至少对于这种特定情况,是使用font 方法:

browser.td(:id, 'Proceed').font.click

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-26
  • 2023-04-01
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
相关资源
最近更新 更多