Search for underlined links in watir

I am trying to find / select a link on an underlined page, while others do not. The source looks something like this:

<a href="someurl1">
<b>
<u>Some ulined text</u>
</b>
<u></u>
</a>
<br>
<a href="someurl2">Other link text</a>
<br>
<a href="someurl3">Another Link text</a>
<br>

I tried something like

link = browser.link(:u?, true)
link.exists?

I get the following errors:

TypeError: expected one of [String, Regexp], got true:TrueClass
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:152:in `check_type'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:189:in `normalized_selector'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:188:in `each'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:188:in `normalized_selector'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:76:in `find_first_by_multiple'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/locators/element_locator.rb:33:in `locate'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:260:in `locate'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:247:in `assert_exists'
    from /usr/lib/ruby/gems/1.8/gems/watir-webdriver-0.2.4/lib/watir-webdriver/elements/element.rb:31:in `exist?'

Edit: Therefore, I actually use this for screen scripting, not for testing. This might explain the reasons why watir doesn't directly support this, since CSS and other best practices make sense for testing, and when you develop and test HTML, hand in hand. Hoserver from a scrambling point of view, text formatting is what the user sees, and searching for underlined, bold links, etc. Make sense for curettage.

+3
source share
3 answers

, . . , .

def hasUnderlined(browser)
  s = false
  browser.links.each do |l| 
    if l.html.downcase.match /\<u\>*\<\/u\>/
      s = true
    end
  end
end

def getUnderlined(browser)
  browser.links.each do |l| 
    if l.html.downcase.match /\<u\>*\<\/u\>/
      return l
    end
  end
end
+1

, , , , , , .

- CSS , , ARE . , , , , , , . , CSS . ( CSS , HTML, html-banana-boat, , , CSS )

, , CSS

, , , - (. @Dave ), watir ..

+1

, , , - ?

, ( watir-webdriver):

browser.link.u.click

:

NoMethodError: undefined method `u' for #<Watir::Anchor:0x00000100cbb3c0>

Jari ( watir-webdriver) , , u HTML.

, :

browser.link.b.click

xpath, , css . :

browser.element(:css => "a b u").click
0
source

All Articles