Question on watir

That’s excellent I understood.

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.

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

Thank you.

RAJ

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

On Mon, Mar 25, 2013 at 6:12 AM, Joel P. [email protected]
wrote:

assignation

So where my head is at…
:slight_smile:

(I know it means assignment as well.)

No,No Just I told you.

RAJ

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

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?

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

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’

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

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

hi I have another question, what is the difference between click and
click_no_wait?

RAJ

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

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

Regarding 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.

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

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

For textbox we are using text_field, what is the corresponding one for
textarea?

RAJ

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