简体   繁体   中英

How to refer to a JavaScript tooltip in Watir

I trying to automate hovering over a tooltip and verify the text in the span class. My code returns true but it gives me a blank statement. My tooltip is written in JavaScript if that helps. # puts $browser.div(:class, 'device_info').p(:class, 'gridfield_tooltip').span(:class, 'title_text').text

Here is the html

在此处输入图片说明

I end up using this:

device_name = $browser.div(:class, 'device_info').div.span(:id, 'FriendlyName').a
device_name.hover 
tooltip = $browser.div(:class, 'device_info').span(:class, 'tooltip_init')
tooltip.hover 
title_text = $browser.div(:class, 'device_info').p(:class, 'gridfield_tooltip').span(:class, 'title_text')
puts title_text.when_present.text

It only prints one line.

The text method only returns currently visible text. An empty string will occur when the element is not visible.

Since this is a tooltip, you need to:

  • Trigger the tooltip to appear and
  • Depending on the implementation, wait for the tooltip to appear (as it is possible that Watir will check the element text before the tooltip finishes being displayed)

This can be accomplished with the hover and when_present methods:

e = $browser.div(:class, 'device_info').p(:class, 'gridfield_tooltip').span(:class, 'title_text')
e.hover
e.when_present.text

If you are only interested in checking the text and not the tooltip functionality itself, you could check the element's inner HTML instead. This would return the title text regardless of whether or not the element is visible.

e = $browser.div(:class, 'device_info').p(:class, 'gridfield_tooltip').span(:class, 'title_text')
e.inner_html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM