Watir :: Exception :: MissingWayOfFindingObjectException:无效属性:: css

时间:2012-01-25 16:26:29

标签: css css-selectors watir watir-webdriver

我很确定watir-webdriver有css选择器支持,但看起来它不再存在了:

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

$ gem -v
1.8.15

$ gem list selenium-webdriver
*** LOCAL GEMS ***
selenium-webdriver (2.17.0)

$ gem list watir-webdriver
*** LOCAL GEMS ***
watir-webdriver (0.4.1)

$ irb
> require "watir-webdriver"
 => true 

> browser = Watir::Browser.new :firefox
 => #<Watir::Browser:0x787eb29124fb7658 url="about:blank" title=""> 

> browser.goto "google.com"
 => "http://www.google.com.mx/" 

> browser.a(:css => "a").flash
Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:228:in `assert_valid_as_attribute'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:209:in `normalize_selector'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:191:in `block in normalized_selector'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:188:in `each'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:188:in `normalized_selector'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:76:in `find_first_by_multiple'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/locators/element_locator.rb:33:in `locate'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/element.rb:285:in `locate'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/element.rb:259:in `assert_exists'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/element.rb:206:in `style'
    from /Users/zeljko/.rvm/gems/ruby-1.9.3-p0/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/element.rb:103:in `flash'
    from (irb):4
    from /Users/zeljko/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'

环境:Mac OS X 10.7.2,Firefox 9.0.1。

我做错了吗?

2 个答案:

答案 0 :(得分:6)

如果您使用Browser#element

,则watir-webdriver目前仅支持此功能
 browser.element(:css => "a")

我们可以添加对其他元素方法的支持,但我们必须找到一种方法来处理例如。

 browser.a(:css => "div.foo")

答案 1 :(得分:3)

有趣,足够我仍然可以绕过很多限制或缺少功能,而不是直接进行JS调用所暴露的功能,例如。

browser.execute_script('jQuery(\'div#td%s div a\').trigger(\'click\')' % reagent_id)

正如我所说,在某些情况下,这对我来说是唯一的方式。将更紧密的集成到DOM中真的很酷。