Ok I understand.
RAJ
Select returns an array, so “first” just picks the top one out for you.
Your code returns a single result as well so I thought this to be the
most suitable option.
Raj pal wrote in post #1104520:
hi I used your code,
my_hash = {
User1=> ‘Pass1’,
User2=> ‘Pass2’
}
That’s not my code, this is:
my_hash = {
User1: ‘Pass1’,
User2: ‘Pass2’
}
This is equivalent to:
my_hash = {
:User1 => ‘Pass1’,
:User2 => ‘Pass2’
}
The reason I used #to_s on the username later was because it is a
symbol, and I used the shortcut notation when creating the hash. The
values themselves are of course placeholders. You can use whatever
content is most suitable.
User1 is a constant (a type of variable), and an uninitialised one in
your case. This is the reason for the error.
Are you sure you’re not out of your depth? After all, you’re trying to
do advanced interactions without being able to work out what lines like
“uninitialized constant User1” mean.
Perhaps you should do some basic tutorials before working on projects
this complex.
I am working in a project, and also I am styding while something new is
needed, I knew of the problem, why i asked was,I don’t have a higher
version, that’s reason i suspect this may be syntax in the higher
version.
RAJ
Enumerable#select is what is being used. This returns an array (a
collection).
I have another question,
h = { “a” => 100, “b” => 200, “c” => 300 }
a=h.select {|k,v| k > “a”}
In the ruby documention they say that it returns hash but it actually
returns the array,what is the reason for this?
RAJ
In 1.8.7:
select {|key, value| block} => array
In 1.9.3 (which I’m currently using), select does indeed return a Hash.
Ok got it.
hi,
If i jump into 1.9.3 ,do i need to face lot of change in my existing
project. My existing project is about automating screen which you might
have known since i have raised lot of question regarding to that.
RAJ
select {|key, value| block} → a_hash click to toggle source
select → an_enumerator
Returns a new hash consisting of entries for which the block returns
true.
If no block is given, an enumerator is returned instead.
h = { “a” => 100, “b” => 200, “c” => 300 }
h.select {|k,v| k > “a”} #=> {“b” => 200, “c” => 300}
h.select {|k,v| v < 200} #=> {“a” => 100}
This is from Ruby Documentation, See this is returning the Hash,not
array,isn’t it?
RAJ
Yes that seems to be a good idea if i have more than one version. And
tell me about Ruby 2.0 if you are to migrate to that.
RAJ
You can run side-by-side installs. I think I’ve heard RVM mentioned in
relation to that.
If I ever get time I’m going to migrate onto Ruby 2.0, so you might want
to look into doing that directly rather than going via 1.9.3 first.
As far as I know Ruby versions are mostly backward compatible regarding
code, apart from the odd hiccup like the behaviour of Hash#select /
Enumerable#select. Operating with multiple versions for a while seems
the best way to manage the upgrade and give time to smooth out any
inconsistency.
Can you tell me how to choose the first element from select_list?
RAJ
hi, Is there any way can I able to highlight the selectbox?Or can i
click the select box so that it would appear with drop down list.
RAJ
I think clicking a select box would probably cause the list to appear.
Try it and see.
If you look at the underlying HTML you’ll often find that a select_list
has values hidden inside the list which are available as an alternative
selection method (select_value).
I think if you want to select an option by its place in the list
(dangerous and prone to errors if the list changes) then you can use
“.options.map(&:text)” to get an array which contains all the options,
then pick whichever one you want from that list.
hi,
Include this question with the above one, when watir places the value in
the text box, it moves the screen towards upwords, can I stop this
screen movement?
RAJ
Raj pal wrote in post #1104861:
Include this question with the above one, when watir places the value in
the text box, it moves the screen towards upwords, can I stop this
screen movement?
I haven’t observed this behaviour, however I should think if it does
this then the solution would be to interact with another element which
makes the screen scroll back down, or interact with the element directly
using a bit of JavaScript.
If you give me the link (or the HTML), and the relevant code, then I can
experiment and see what I can come up with.
Ok thank you, And that url is available in internal server,it’s not
available outside.
RAJ
hi,
I have a question,
$browser.elements.each do |t|
puts t
end
Is there anything wrong in the above code, it’s giving the error,
" each_element': undefined method
each’ for nil:NilClass
(NoMethodError)"
Can’t apply each method for elements?
RAJ
Am 12.04.2013 07:48, schrieb Raj pal:
(NoMethodError)"
Can’t apply each method for elements?
RAJ
Try
p $browser.elements
or puts $browser.elements.inspect
and you will see what the problem is.