# 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:** 8

<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:** [March 22, 2013, 5:14pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/141 "2013-03-22T17:14:37Z")

</div>

That’s excellent I understood.

---

<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:** [March 25, 2013, 12:12pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/142 "2013-03-25T12:12:22Z")

</div>

Works for me:

irb(main):001:0\> require ‘watir’  
=\> true  
irb(main):002:0\> 100.times { |t|  
\<atir::Browser.attach( :index, t ) ).title rescue break  
irb(main):004:1\> }  
Google  
Gmail: Email from Google  
=\> nil  
irb(main):005:0\>

All you’re doing with your code there is constantly reassigning the  
variable $browser but not doing anything with it. The code you posted  
doesn’t “work” in the same sense as the example I gave.  
The reason that I don’t use assignation is because I’m only doing 1  
thing inside the loop, I don’t need to use a variable for that.  
If you’re experiencing issues then could be down to Ruby or Watir  
versions, IE add-ons, typos in the code, or all sorts of different  
possibilities.

---

<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:** [March 25, 2013, 3:14pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/143 "2013-03-25T15:14:10Z")

</div>

Ok, Since I am using Ruby 1.8.7, this problem might have occured.

Thank you.

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:** [March 25, 2013, 7:41am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/144 "2013-03-25T07:41:14Z")

</div>

hi Joel P.,

100.times { |t|  
puts ( Watir::Browser.attach( :index, t ) ).title rescue break  
}

This code fails to execute because you haven’t return the browser  
instance, But now I modified your code like given below

100.times do |t|  
$browser=Watir::Browser.attach( :index, t ) rescue break  
end

This code works. Why your code is not working? did you meant to say  
include something with your code thereby it will work?Did I miss  
anything in your code?

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:** [March 25, 2013, 7:49pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/145 "2013-03-25T19:49:09Z")

</div>

On Mon, Mar 25, 2013 at 6:12 AM, Joel P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> assignation

So where my head is at…  
🙂

(I know it means assignment as well.)

---

<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:** [March 26, 2013, 5:56am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/146 "2013-03-26T05:56:06Z")

</div>

No,No Just I told you.

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:** [March 26, 2013, 7:56am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/147 "2013-03-26T07:56:35Z")

</div>

hi,

Look at the below code,

| | |

Now from the above table I need to print the title using ruby code? How  
can i write the code? Because If we want to take something from the  
column then we can write the code like  
$browser.table().td(:title,‘hi’).text

But I want the title to be printed,Is it possible?

And currently i am using this code to print the value of inner text,

iActual =  
tempHTML.xpath(".//div[@id=‘Dashboard’]//div[@id=‘DashboardDetails’]//table[@class=‘Panel’]//tbody//tr[3]//td[4]//label").inner\_text

So i able to print the title from td , i will not be in need the above  
code.  
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:** [March 26, 2013, 3:23pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/148 "2013-03-26T15:23:13Z")

</div>

OK, Thank you.

consider this code,

$browser.text\_field(:id,‘Date’).set(‘raja’)  
puts ‘raja’  
popupMsg=modalDialog(‘Ok’)

hi look at the above code, I am setting the wrong string ‘raja’ in the  
date field, so it gives the pop up, Now i have written the pop up  
handler below “modelDialog”, Now the problem is, as soon as pop comes  
next line is not executed, in this case puts ‘raja’ is not executed,  
that means control is not coming to the next line, so it is not reaching  
the function call of modalDialog(‘Ok’), How can i transfer the control  
to the next line while pop is visible?

---

<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:** [March 26, 2013, 9:30am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/149 "2013-03-26T09:30:17Z")

</div>

This will flash every cell with a title in the first table it finds (for  
some reason passing a single dot makes it include ones with no title).  
Just deconstruct it and rebuild to do what you want with it.

b.tables.first.tds(:title, /…/).each &:flash

---

<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:** [March 26, 2013, 3:38pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/150 "2013-03-26T15:38:26Z")

</div>

If you mean that there’s an alert appearing immediately after you set  
the text field, you’d need to do something like this:

$browser.text\_field(:id,‘Date’).set(‘raja’)  
$browser.alert.close  
puts ‘raja’

---

<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:** [March 27, 2013, 10:44am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/151 "2013-03-27T10:44:51Z")

</div>

Thank you.

hi,

b.tables.first.tds(:title, /…/).each &:flash

Can you re-define this above line for textfields? for an example i want  
to reflect the title in username and password for Gmail.Is it possible?

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:** [March 27, 2013, 11:36am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/152 "2013-03-27T11:36:28Z")

</div>

In the case of gmail, this would do it.  
b.text\_fields.each { |t| t.parent.labels.first.flash }

---

<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:** [March 26, 2013, 3:37pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/153 "2013-03-26T15:37:40Z")

</div>

hi I have another question, what is the difference between click and  
click\_no\_wait?

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:** [March 27, 2013, 12:37pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/154 "2013-03-27T12:37:34Z")

</div>

b.text\_fields.each { |t| puts t.parent.labels.first.text }(I made it as  
text to print the value)

This above code perfectly working for Gmail, But for some screens, it  
says that  
" undefined method `text’ for nil:NilClass", what is the problem here?

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:** [March 27, 2013, 12:57pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/155 "2013-03-27T12:57:03Z")

</div>

hi,  
$browser.link(:id,‘click’).when\_present.click

Here we are giving when\_present to make sure that link is available in  
the browser. Now, sometimes when the combobox delays to populate the  
values, in such cases my program clicks the combo box and checks the  
element and it found nothing, but if it had pressed after few seconds  
elements would have been found. Is there any function like when\_present  
available for combo to check when elements gets populated or not?

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:** [March 27, 2013, 1:09pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/156 "2013-03-27T13:09:37Z")

</div>

Regarding waiting:  
[http://watirwebdriver.com/waiting/](http://watirwebdriver.com/waiting/)

Watir::Wait.until { ( Code to check Combobox has your value… ) }

Regarding NilClass, the code I gave is assuming that the text field is  
inside a label, like in the gmail page. If this is not the case, you  
will get nil for the parent’s label. You need to adapt the code to the  
structure of your page.

---

<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:** [March 27, 2013, 2:31pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/157 "2013-03-27T14:31:07Z")

</div>

Regarding NilClass, the code I gave is assuming that the text field is  
inside a label, like in the gmail page. If this is not the case, you  
will get nil for the parent’s label. You need to adapt the code to the  
structure of your page.

ok

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:** [March 27, 2013, 1:20pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/158 "2013-03-27T13:20:08Z")

</div>

Hi,

It’s working fine, I have given like

Watir::Wait.until{$b.select\_list(:id,‘hi’).select(‘hello’)}

Now it’s working fine.

Thank you.

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:** [March 28, 2013, 8:27am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/159 "2013-03-28T08:27:19Z")

</div>

For textbox we are using text\_field, what is the corresponding one for  
textarea?

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:** [March 28, 2013, 8:02am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/160 "2013-03-28T08:02:46Z")

</div>

hi,

I redefined your code according to my necessity,

[:text\_fields, :select\_lists, :checkboxes].each do |type|  
$browser.send(type).each do |i|  
if type.to\_s[0…-2].eql?(‘text\_field’)  
puts “$browser.text\_field(:id,’#{i.id}’).set(‘rajagopalan’)”  
elsif type.to\_s[0…-2].eql?(‘select\_list’)  
puts “$browser.select\_list(:id,’#{i.id}’).select(‘RAJ’)”  
elsif type.to\_s[0…-3].eql?(‘checkbox’)  
puts “$browser.checkbox(:id,’#{i.id}’).set”  
end  
end  
end

Now, it actually takes all the text box first and then it goes to the  
select\_list and then it goes to the checkbox. But I want to be an order  
the way they are situated in screen, Is it possible to get like that?

RAJ

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

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