Re: [wtr-general] Re: Select an element when :id and :class are not completely known
On Thu, Aug 19, 2010 at 12:54 AM, jasbro jas...@gmail.com wrote: This may just be a benefit of using Ruby, or it may have been intentional Intentional. More info: http://wiki.openqa.org/display/WTR/How+and+What http://wiki.openqa.org/display/WTR/Summary Željko -- watir.com - community manager watirpodcast.com - host testingpodcast.com - audio podcasts on software testing. all of them vidipodkast.com - pričamo o hardveru, softveru i časopisu Vidi -- 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
[wtr-general] Re: Select an element when :id and :class are not completely known
There you go. that's what I was about to suggest. as long as you're able to create a regex that won't match more than one classname, you are in business. Another alternative (if you have control over what's being created) might be to also have the jQuery code assign a 'name' to the element, hopefully without a random number appended (which I presume is done to generate ID's guaranteed to be unique) and identify it by the name. On Aug 18, 3:54 pm, jasbro jas...@gmail.com wrote: 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
[wtr-general] Re: Select an element when :id and :class are not completely known
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