質問

I'm trying to click on a tag with watir classic 3.7.0 which is unsupported. Generally, it looks as though I can find the tag with a line such as:

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

and

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

returns watir::HTMLElement, but I cannot find any documentation for this (only Element)

using

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

shows that it has the method click, but running

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

results in :

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

I have tried making a module for the font tag:

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

but this throws the error,

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

How do I click on this unsupported tag?

役に立ちましたか?

解決

It looks like you are running into Issue 62.

Solution 1 - Upgrade Watir-Classic

This bug is fixed in the latest version of watir-classic. Note that you need to upgrade the watir-classic gem (not just the watir gem):

gem install watir-classic

Solution 2 - Use an Array

If upgrading to the latest version is not an option, you can make the :tag_name value an array:

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

Solution 3 - Use font method

I just double-checked and the font element is actually supported. So I would say the better solution, for this specific case at least, would be to use the font method:

browser.td(:id, 'Proceed').font.click
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top