Read text file and check multiple checkbox

Hi Friends,

     I try to check the Multiple Checkboxes in the page.

first i read the value in the text file and assing it to the variable.
but the problem is that at the time only one check box are selected.

textfile values:
selectedLocationOids=0000025354000000630d
selectedLocationOids=000002527100000062bc


HTML Code:


RUBY Script:
require ‘watir’
include Watir
require ‘logger’

opts = {}
File.open(“c:/test/Flow1.txt”) do |f|
f.each_line do |line|
opts[$1] = $2 if line =~ /^(.)=(.)$/
end
end
@check_location = opts[“selectedLocationOids”]
@check_location1 = opts[“selectedLocationOids”]

ie.checkbox(:value,@check_location).set()
ie.checkbox(:value,@check_location1).set()

KingMaker KingMaker wrote:

Hi Friends,

     I try to check the Multiple Checkboxes in the page.

first i read the value in the text file and assing it to the variable.
but the problem is that at the time only one check box are selected.

textfile values:
selectedLocationOids=0000025354000000630d
selectedLocationOids=000002527100000062bc


In the example that you provided it seems that value of @check_location
is equal to the value of @check_location1. Shouldn’t they be different?

On Thu, May 20, 2010 at 8:05 AM, KingMaker KingMaker
[email protected]wrote:



end

In addition to what Marcin said:
*Your html can’t have two elements with the same ID (ID’s must be
unique,
like a social security number)
*Your inputs should end with /> instead of just > to close the tag.
*Since they are checkboxes, they should also have different names. The
name
is what determines the name of the key that the server receives, so when
you
have two inputs whose names are selectedLocationOids, then clicking both
causes one to be overwritten.

To illustrate, when I submit your form, my server receives:
Submitting with neither box checked
Parameters: {“commit”=>“Create”,
“authenticity_token”=>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with the first box checked
Parameters: {“commit”=>“Create”,
“selectedLocationOids”=>“0000025354000000630d”,
“authenticity_token”=>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with the second box checked
Parameters: {“commit”=>“Create”,
“selectedLocationOids”=>“000002527100000062bc”,
“authenticity_token”=>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with both boxes checked
Parameters: {“commit”=>“Create”,
“selectedLocationOids”=>“000002527100000062bc”,
“authenticity_token”=>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

You can see that that even with both boxes checked, only receive one
value,
because they both have the same name. It might help you to read up on
how
hash tables work (Hash table - Wikipedia)

  • I’m on a Mac, so I can’t check your example, but I’m not sure what
    “ie”
    is. It looks like a variable ,but could be a method. If it is a method,
    I
    don’t see anything like it for Firefox, and their examples do not seem
    to
    behave the way you have used it (Redirecting…) If it is a
    variable, then where was it initialized? It looks like you need to say
    ie =
    Browser.start(“http://your-url.com”)