After I posted this question, I started thinking that the best
solution would be if I could use a regular expression to select the
element:
  @browser.div(:id,/^amount_.*/)
or
  @browser.div(:class,/.*amount.*/)

So I tried it, and it worked for both Firefox and IE.  This may just
be a benefit of using Ruby, or it may have been intentional (I don't
know...I'm a Java guy) but I'm really glad it worked.  Hope anyone
else who comes across this question finds this useful.


On Aug 18, 2:40 pm, jasbro <jas...@gmail.com> wrote:
> In the jQuery world, it isn't uncommon for me to dynamically add
> classes to an element.  Depending on various circumstances, the class
> of a div might be something like "amount" or "amount required" or
> "amount required invalid".  In my particular situation, the problem is
> compounded by the fact that my id is partially made up of a random
> number, so I can't simply do div(:id,"amount").  What I do know is the
> first chunk of the id (e.g. it always starts with "amount_").  I also
> know that the class will always contain "amount", though it may also
> contain additional classes.  An example:
>   <div id="amount_1239783" class="required amount invalid">...</div>
>
> 1. I've tried to do @ff.div(:class,"amount") but it only works if they
> other classes haven't been added
> 2. I know I can do @ff.div(:class,"required amount invalid") but
> sometimes the classes get added in a different order (and some classes
> don't get added every time, so maintaining all the possible
> combinations is ridiculous)
> 3. I know I can do "each" through the divs looking to see if the class
> contains the given value, or the id starts with amount, but that seems
> excessive
>
> Does anyone know if there is a simple way to do this?

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

You received this message because you are subscribed to 
http://groups.google.com/group/watir-general
To post: watir-general@googlegroups.com
To unsubscribe: watir-general+unsubscr...@googlegroups.com

Reply via email to