# Question on watir

**URL:** <https://www.ruby-forum.com/t/question-on-watir/224437>\
**Category:** Ruby\
**Created:** [November 12, 2012, 5:45am UTC](https://www.ruby-forum.com/t/question-on-watir/224437 "2012-11-12T05:45:39Z")\
**Posts on this page:** 20\
**Page:** 11

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:12pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/201 "2013-04-05T13:12:38Z")

</div>

Ok I understand.  
RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:12pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/202 "2013-04-05T13:12:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:17pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/203 "2013-04-05T13:17:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:30pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/204 "2013-04-05T13:30:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:50pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/205 "2013-04-05T13:50:44Z")

</div>

Enumerable#select is what is being used. This returns an array (a  
collection).

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:31pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/206 "2013-04-05T13:31:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 2:02pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/207 "2013-04-05T14:02:11Z")

</div>

In 1.8.7:  
select {|key, value| block} =\> array

In 1.9.3 (which I’m currently using), select does indeed return a Hash.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 2:06pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/208 "2013-04-05T14:06:20Z")

</div>

Ok got it.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 2:08pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/209 "2013-04-05T14:08:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 1:54pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/210 "2013-04-05T13:54:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 3:42pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/211 "2013-04-05T15:42:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 5, 2013, 2:31pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/212 "2013-04-05T14:31:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 6, 2013, 11:48am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/213 "2013-04-06T11:48:34Z")

</div>

Can you tell me how to choose the first element from select\_list?

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 6, 2013, 11:19am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/214 "2013-04-06T11:19:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 10, 2013, 9:01pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/215 "2013-04-10T21:01:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 8, 2013, 7:22am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/216 "2013-04-08T07:22:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 10, 2013, 9:04pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/217 "2013-04-10T21:04:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 12, 2013, 7:46am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/218 "2013-04-12T07:46:43Z")

</div>

Ok thank you, And that url is available in internal server,it’s not  
available outside.

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 12, 2013, 7:48am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/219 "2013-04-12T07:48:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 12, 2013, 7:55am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/220 "2013-04-12T07:55:48Z")

</div>

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.

[Previous page](https://www.ruby-forum.com/t/question-on-watir/224437.md?page=10)

[Next page](https://www.ruby-forum.com/t/question-on-watir/224437.md?page=12)
