From kcampos at bioiq.com Fri Jan 11 15:13:31 2008 From: kcampos at bioiq.com (Kyle Campos) Date: Fri, 11 Jan 2008 13:13:31 -0700 Subject: [SafariWatir-general] How to get the value of a checkbox Message-ID: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> The set method for checkbox class unfortunately just does blind checking. So if the checkbox is already checked and you call .set on it, then it will uncheck it. I'm not sure if this is a safari-watir issue or watir. In either case I could account for this if I was able to get the value of a checkbox, and basically do a if(value==0) {checkbox.set}. I tried adding the following in the checkbox class: def getValue @scripter.get_value_for(self) end But that always returns 1, not sure why. Anyone know how to properly obtain the value or checked status? Any help would be appreciated. -Kyle From kcampos at bioiq.com Fri Jan 11 17:32:28 2008 From: kcampos at bioiq.com (Kyle Campos) Date: Fri, 11 Jan 2008 15:32:28 -0700 Subject: [SafariWatir-general] How to get the value of a checkbox In-Reply-To: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> References: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> Message-ID: <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> I found a solution. In case anyone is interested here's what I did: scripter.rb: > def checkbox_is_checked?(element = @element) > execute(element.operate { %|return element.checked;| }, element) > end safariwatir.rb: class Checkbox < InputElement ... > def isChecked? > @scripter.checkbox_is_checked?(self) > end And then I wrap .set with this login in my own function: def enable_checkbox(selector, value) unless(@@browser.checkbox(selector, value).isChecked?) @@browser.checkbox(selector, value).set end end So in my tests I do: enabled_checkbox(:name, "test") Again this is all so that you insure the final value of a checkbox is checked. checkbox.set just blindly checks the checkbox no matter what the current status is. -Kyle On Jan 11, 2008, at 1:13 PM, Kyle Campos wrote: > The set method for checkbox class unfortunately just does blind > checking. So if the checkbox is already checked and you call .set on > it, then it will uncheck it. I'm not sure if this is a safari-watir > issue or watir. In either case I could account for this if I was > able to get the value of a checkbox, and basically do a if(value==0) > {checkbox.set}. > > I tried adding the following in the checkbox class: > > def getValue > @scripter.get_value_for(self) > end > > But that always returns 1, not sure why. Anyone know how to properly > obtain the value or checked status? > > Any help would be appreciated. > -Kyle From dave at obtiva.com Fri Jan 11 17:39:13 2008 From: dave at obtiva.com (Dave Hoover) Date: Fri, 11 Jan 2008 16:39:13 -0600 Subject: [SafariWatir-general] How to get the value of a checkbox In-Reply-To: <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> References: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> Message-ID: <11c8704e0801111439l2df75beav3ef9ae2c4597aa21@mail.gmail.com> Kyle, thanks for digging into this. My schedule is still preventing me from touching SafariWatir these days, though this problem could probably be resolved quickly. I'll do my best to figure out the correct behavior from the main Watir project and clone that over the weekend. Best, Dave Hoover //obtiva: Agility applied. Software delivered. On Jan 11, 2008 4:32 PM, Kyle Campos wrote: > I found a solution. In case anyone is interested here's what I did: > > scripter.rb: > > > def checkbox_is_checked?(element = @element) > > execute(element.operate { %|return element.checked;| }, element) > > end > > safariwatir.rb: > > class Checkbox < InputElement > ... > > def isChecked? > > @scripter.checkbox_is_checked?(self) > > end > > And then I wrap .set with this login in my own function: > > def enable_checkbox(selector, value) > unless(@@browser.checkbox(selector, value).isChecked?) > @@browser.checkbox(selector, value).set > end > end > > So in my tests I do: enabled_checkbox(:name, "test") > > Again this is all so that you insure the final value of a checkbox is > checked. checkbox.set just blindly checks the checkbox no matter what > the current status is. > > -Kyle > > > On Jan 11, 2008, at 1:13 PM, Kyle Campos wrote: > > > The set method for checkbox class unfortunately just does blind > > checking. So if the checkbox is already checked and you call .set on > > it, then it will uncheck it. I'm not sure if this is a safari-watir > > issue or watir. In either case I could account for this if I was > > able to get the value of a checkbox, and basically do a if(value==0) > > {checkbox.set}. > > > > I tried adding the following in the checkbox class: > > > > def getValue > > @scripter.get_value_for(self) > > end > > > > But that always returns 1, not sure why. Anyone know how to properly > > obtain the value or checked status? > > > > Any help would be appreciated. > > -Kyle From dave at obtiva.com Fri Jan 11 23:43:13 2008 From: dave at obtiva.com (Dave Hoover) Date: Fri, 11 Jan 2008 22:43:13 -0600 Subject: [SafariWatir-general] How to get the value of a checkbox In-Reply-To: <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> References: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> Message-ID: <11c8704e0801112043g42a5d706y95b6fca9013f6167@mail.gmail.com> Kyle, I found some time tonight to integrate your contributions and I released a new gem (0.2.6). Thanks! Best, Dave Hoover //obtiva: Agility applied. Software delivered. On 1/11/08, Kyle Campos wrote: > I found a solution. In case anyone is interested here's what I did: > > scripter.rb: > > > def checkbox_is_checked?(element = @element) > > execute(element.operate { %|return element.checked;| }, element) > > end > > safariwatir.rb: > > class Checkbox < InputElement > ... > > def isChecked? > > @scripter.checkbox_is_checked?(self) > > end > > And then I wrap .set with this login in my own function: > > def enable_checkbox(selector, value) > unless(@@browser.checkbox(selector, value).isChecked?) > @@browser.checkbox(selector, value).set > end > end > > So in my tests I do: enabled_checkbox(:name, "test") > > Again this is all so that you insure the final value of a checkbox is > checked. checkbox.set just blindly checks the checkbox no matter what > the current status is. > > -Kyle > > On Jan 11, 2008, at 1:13 PM, Kyle Campos wrote: > > > The set method for checkbox class unfortunately just does blind > > checking. So if the checkbox is already checked and you call .set on > > it, then it will uncheck it. I'm not sure if this is a safari-watir > > issue or watir. In either case I could account for this if I was > > able to get the value of a checkbox, and basically do a if(value==0) > > {checkbox.set}. > > > > I tried adding the following in the checkbox class: > > > > def getValue > > @scripter.get_value_for(self) > > end > > > > But that always returns 1, not sure why. Anyone know how to properly > > obtain the value or checked status? > > > > Any help would be appreciated. > > -Kyle > > _______________________________________________ > SafariWatir-general mailing list > SafariWatir-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/safariwatir-general From kcampos at bioiq.com Sat Jan 12 01:31:52 2008 From: kcampos at bioiq.com (Kyle Campos) Date: Fri, 11 Jan 2008 23:31:52 -0700 Subject: [SafariWatir-general] How to get the value of a checkbox In-Reply-To: <11c8704e0801112043g42a5d706y95b6fca9013f6167@mail.gmail.com> References: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> <11c8704e0801112043g42a5d706y95b6fca9013f6167@mail.gmail.com> Message-ID: <1C7C8143-19D8-49BA-875C-5B3DEF9B9DE6@bioiq.com> Great! Thanks for the quick response. -Kyle On Jan 11, 2008, at 9:43 PM, Dave Hoover wrote: > Kyle, > > I found some time tonight to integrate your contributions and I > released a new gem (0.2.6). Thanks! > > Best, > > Dave Hoover > //obtiva: Agility applied. Software delivered. > > > On 1/11/08, Kyle Campos wrote: >> I found a solution. In case anyone is interested here's what I did: >> >> scripter.rb: >> >>> def checkbox_is_checked?(element = @element) >>> execute(element.operate { %|return element.checked;| }, element) >>> end >> >> safariwatir.rb: >> >> class Checkbox < InputElement >> ... >>> def isChecked? >>> @scripter.checkbox_is_checked?(self) >>> end >> >> And then I wrap .set with this login in my own function: >> >> def enable_checkbox(selector, value) >> unless(@@browser.checkbox(selector, value).isChecked?) >> @@browser.checkbox(selector, value).set >> end >> end >> >> So in my tests I do: enabled_checkbox(:name, "test") >> >> Again this is all so that you insure the final value of a checkbox is >> checked. checkbox.set just blindly checks the checkbox no matter what >> the current status is. >> >> -Kyle >> >> On Jan 11, 2008, at 1:13 PM, Kyle Campos wrote: >> >>> The set method for checkbox class unfortunately just does blind >>> checking. So if the checkbox is already checked and you call .set on >>> it, then it will uncheck it. I'm not sure if this is a safari-watir >>> issue or watir. In either case I could account for this if I was >>> able to get the value of a checkbox, and basically do a if(value==0) >>> {checkbox.set}. >>> >>> I tried adding the following in the checkbox class: >>> >>> def getValue >>> @scripter.get_value_for(self) >>> end >>> >>> But that always returns 1, not sure why. Anyone know how to properly >>> obtain the value or checked status? >>> >>> Any help would be appreciated. >>> -Kyle >> >> _______________________________________________ >> SafariWatir-general mailing list >> SafariWatir-general at rubyforge.org >> http://rubyforge.org/mailman/listinfo/safariwatir-general From dave at obtiva.com Sat Jan 12 09:28:54 2008 From: dave at obtiva.com (Dave Hoover) Date: Sat, 12 Jan 2008 08:28:54 -0600 Subject: [SafariWatir-general] How to get the value of a checkbox In-Reply-To: <1C7C8143-19D8-49BA-875C-5B3DEF9B9DE6@bioiq.com> References: <87C91DAE-CE71-459F-944E-B69BA75B3578@bioiq.com> <2E442C9B-71A6-4BDF-965A-2FEEA86BD927@bioiq.com> <11c8704e0801112043g42a5d706y95b6fca9013f6167@mail.gmail.com> <1C7C8143-19D8-49BA-875C-5B3DEF9B9DE6@bioiq.com> Message-ID: <11c8704e0801120628x3a762ed2tb005a21fe37564d6@mail.gmail.com> The Checkbox#set behavior now works like Watir's. If you call browser.checkbox(...).set(true) or browser.checkbox(...).set, it will check the checkbox. Call browser.checkbox(...).set(false) to clear it. On 1/12/08, Kyle Campos wrote: > Great! Thanks for the quick response. > > -Kyle > > On Jan 11, 2008, at 9:43 PM, Dave Hoover wrote: > > > Kyle, > > > > I found some time tonight to integrate your contributions and I > > released a new gem (0.2.6). Thanks! > > > > Best, > > > > Dave Hoover > > //obtiva: Agility applied. Software delivered. > > > > > > On 1/11/08, Kyle Campos wrote: > >> I found a solution. In case anyone is interested here's what I did: > >> > >> scripter.rb: > >> > >>> def checkbox_is_checked?(element = @element) > >>> execute(element.operate { %|return element.checked;| }, element) > >>> end > >> > >> safariwatir.rb: > >> > >> class Checkbox < InputElement > >> ... > >>> def isChecked? > >>> @scripter.checkbox_is_checked?(self) > >>> end > >> > >> And then I wrap .set with this login in my own function: > >> > >> def enable_checkbox(selector, value) > >> unless(@@browser.checkbox(selector, value).isChecked?) > >> @@browser.checkbox(selector, value).set > >> end > >> end > >> > >> So in my tests I do: enabled_checkbox(:name, "test") > >> > >> Again this is all so that you insure the final value of a checkbox is > >> checked. checkbox.set just blindly checks the checkbox no matter what > >> the current status is. > >> > >> -Kyle > >> > >> On Jan 11, 2008, at 1:13 PM, Kyle Campos wrote: > >> > >>> The set method for checkbox class unfortunately just does blind > >>> checking. So if the checkbox is already checked and you call .set on > >>> it, then it will uncheck it. I'm not sure if this is a safari-watir > >>> issue or watir. In either case I could account for this if I was > >>> able to get the value of a checkbox, and basically do a if(value==0) > >>> {checkbox.set}. > >>> > >>> I tried adding the following in the checkbox class: > >>> > >>> def getValue > >>> @scripter.get_value_for(self) > >>> end > >>> > >>> But that always returns 1, not sure why. Anyone know how to properly > >>> obtain the value or checked status? > >>> > >>> Any help would be appreciated. > >>> -Kyle > >> > >> _______________________________________________ > >> SafariWatir-general mailing list > >> SafariWatir-general at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/safariwatir-general > > -- Dave Hoover //obtiva: Agility applied. Software delivered. From kcampos at bioiq.com Wed Jan 16 13:25:59 2008 From: kcampos at bioiq.com (Kyle Campos) Date: Wed, 16 Jan 2008 11:25:59 -0700 Subject: [SafariWatir-general] added wait_for methods to avoid arbitrary sleeps Message-ID: <99A28E63-6CCC-4C0B-B4B3-62F4E79A8E49@bioiq.com> I've seen the discussion on the bug in safari's ready state that has lead to issues with the watir going to the next operation before the browser is ready. I myself experience that same issue. Outside of addressing the bug in safari the best way around this is for wait_for methods, not arbitrary sleeps. So what I did is add 2 methods, wait_for_exist which wraps exists? and wait_for_text which wraps contains_text. This allows you to move as fast as your browser is going without wasting any time or going too fast. Here's the code in safariwatir.rb: class HtmlElement ... Line 69: > def wait_for_exist(interval = 1, tries = 30) > attempts = 1 > until (self.exists? or (attempts == tries)) > sleep(interval) > attempts += 1 > end > return (attempts < tries ? true : false) > end and # Elements ... Line 423: > def wait_for_text(what, interval = 1, tries = 30) > attempts = 1 > until (self.contains_text(what) or (attempts == tries)) > sleep(interval) > attempts += 1 > end > return (attempts < tries ? true : false) > end You could and probably should provide a class variable that defines the default try number and provide a method to set that in the Safari class similar to DEFAULT_TYPING_LAG. I left that out here just for sake of clarity. Hope this useful, comments appreciated. Thanks -- Kyle Campos kcampos at bioiq.com Skype: kyle.campos From kcampos at bioiq.com Thu Jan 17 11:51:37 2008 From: kcampos at bioiq.com (Kyle Campos) Date: Thu, 17 Jan 2008 09:51:37 -0700 Subject: [SafariWatir-general] Any plans to get operate_by_name working with reg exp? Message-ID: I really need to be able to do the following: browser.text_field(:name, /something/).set(blah). I believe this is supported in watir itself, at least it is in the documentation. Any plans to clone this behavior? -Kyle -- Kyle Campos kcampos at bioiq.com Skype: kyle.campos From bret at pettichord.com Sat Jan 19 08:20:32 2008 From: bret at pettichord.com (Bret Pettichord) Date: Sat, 19 Jan 2008 07:20:32 -0600 Subject: [SafariWatir-general] added wait_for methods to avoid arbitrary sleeps In-Reply-To: <99A28E63-6CCC-4C0B-B4B3-62F4E79A8E49@bioiq.com> References: <99A28E63-6CCC-4C0B-B4B3-62F4E79A8E49@bioiq.com> Message-ID: <4791F920.3030101@pettichord.com> Another option would be to use Watir's wait_until method, which is pure Ruby and not IE or Windows specific. It can be used thus: wait_until {browser.div(:id, 'spam').exists?} wait_until {browser.div(:id, 'spam').contains_text(what)} Bret Kyle Campos wrote: > I've seen the discussion on the bug in safari's ready state that has > lead to issues with the watir going to the next operation before the > browser is ready. I myself experience that same issue. Outside of > addressing the bug in safari the best way around this is for wait_for > methods, not arbitrary sleeps. So what I did is add 2 methods, > wait_for_exist which wraps exists? and wait_for_text which wraps > contains_text. This allows you to move as fast as your browser is > going without wasting any time or going too fast. > > Here's the code in safariwatir.rb: > > class HtmlElement > ... > Line 69: > > def wait_for_exist(interval = 1, tries = 30) > > attempts = 1 > > until (self.exists? or (attempts == tries)) > > sleep(interval) > > attempts += 1 > > end > > return (attempts < tries ? true : false) > > end > > and > > # Elements > ... > Line 423: > > def wait_for_text(what, interval = 1, tries = 30) > > attempts = 1 > > until (self.contains_text(what) or (attempts == tries)) > > sleep(interval) > > attempts += 1 > > end > > return (attempts < tries ? true : false) > > end > > You could and probably should provide a class variable that defines > the default try number and provide a method to set that in the Safari > class similar to DEFAULT_TYPING_LAG. I left that out here just for > sake of clarity. > > Hope this useful, comments appreciated. > Thanks > > -- > Kyle Campos > kcampos at bioiq.com > Skype: kyle.campos > > > > > _______________________________________________ > SafariWatir-general mailing list > SafariWatir-general at rubyforge.org > http://rubyforge.org/mailman/listinfo/safariwatir-general > -- Bret Pettichord Lead Developer, Watir, http://wtr.rubyforge.org Blog, http://www.io.com/~wazmo/blog