Read text file and check multiple checkbox

  • Thread starter KingMaker KingMaker
  • Start date
K

KingMaker KingMaker

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:

<input type="checkbox" value="0000025354000000630d"
name="selectedLocationOids" id="selectedLocationOids"
class="vmCheckbox">

<input type="checkbox" value="000002527100000062bc"
name="selectedLocationOids" id="selectedLocationOids"
class="vmCheckbox">
______________________________________________________________________________

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()
 
M

Marcin Wolski

KingMaker said:
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?
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

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:

<input type="checkbox" value="0000025354000000630d"
name="selectedLocationOids" id="selectedLocationOids"
class="vmCheckbox">

<input type="checkbox" value="000002527100000062bc"
name="selectedLocationOids" id="selectedLocationOids"
class="vmCheckbox">

______________________________________________________________________________

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()

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 (http://en.wikipedia.org/wiki/Hash_table)

* 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 (http://watir.com/examples/) If it is a
variable, then where was it initialized? It looks like you need to say ie =
Browser.start("http://your-url.com")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top