ruby - Watir get INNER html of -



ruby - Watir get INNER html of <span> -

i'm trying find navigation link iterating through handful of spans class 'menu-item-text'. goal compare within span tags see if right navigation command click (there no hard ids go by.) code this:

navlinks = @browser.spans(:class, 'menu-item') navlinks.each |this| puts "'#{this.text}'" if this.text == link_name this.click break end

i know sure i'm getting right elements. however, text empty string. sec thought utilize .html instead of .text, returns this:

<span class="menu-item">insights</span>

what want "insights" text within span, not total html includes tag markup. have tried using this.span.text, did not work either.

how can target exclusively inner html of element through watir's content grabbing methods?

thanks!

assuming using watir-webdriver v0.6.9 or later, inner_html method has been added getting inner html.

for span:

<span class="menu-item">insights</span>

you do:

@browser.span(:class => 'menu-item').inner_html #=> "insights"

similarly, seek using method in loop instead of .text.

note depending on uniqueness of text, might able check if text appears in element's (outer) html:

@browser.spans(:class => 'menu-item', :html => /#{link_name}/).click

html ruby cucumber watir

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -