简体   繁体   中英

Using wildcards in ruby/watir

I'm controlling an IE page using watir.

I have this command:-

browser.frame(:id,"ultraposuidialoghtm0").div(:class," content").button(:id,"ok").click

However the ultraposuidialoghtm0 part increments, so I get ultraposuidialoghtm1 etc.

How do I label my id as ultraposuidialoghtm* ?

It looks like it supports regular expressions in method calls . Maybe it's worth trying something like:

browser
  .frame(:id, /ultraposuidialoghtm[0-9]*/)
  .div(:class," content")
  .button(:id, "ok")
  .click

I can't really test it at the moment, but it might be wort checking!

Good luck!

If id values are being used in accordance with the html spec, then they are unique within a page or frame. In that case you can use

browser
  .frame(:id, /ultraposuidialoghtm[0-9]*/)
  .button(:id, "ok").click

Using regular expressions can be slow however, so if the number and order of frames on the page is known, or if the frame is contained by some other easy to find container element, then you might want to locate by index, or just the first frame inside the container.

browser.div(:class => 'frame holder').frame.button(:id => 'ok').click

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