OK thank you.
hi,
tests = method_names.delete_if { |method_name| method_name !~ /^test/ }
while I am trying to execute this line, it says that
" undefined method `delete_if’ for “test_1”:String (NoMethodError)"
What should I do to work with this delete_if method?
Raj
delete_if is an array method, it looks like you’re trying to run it
against a string.
Yes I got it. Thank you.
This was done with watir-webdriver, not selenium-webdriver, so it
handles the page load waiting and timeout raising by itself.
The reason I used purple.com is because it’s the fastest-loading page on
the internet, so it will look very quick.
If you want to account for the browser’s opening time as well, then you
could do something like this:
Timeout.timeout(10) do
b = Watir::Browser.new
b.goto(‘www.purple.com’)
b.close
end
hi consider your program
def mymethod
b = Watir::Browser.new
b.goto ‘www.purple.com’
b.close
return true
rescue Timeout::Error
puts “Page load timed out”
return false
rescue => e
puts e
return false
ensure
b.close rescue nil
end
10.times do |iteration|
unless mymethod
puts “Error occurred, terminating process”
exit
else
puts “Succeeded: #{iteration}”
end
end
This program opens the browser by executing the statement
b.open “www.purple.com” and then it immediately closes the browser
regardless of loading status of the browser. That means it executes the
statement www.purple.com and once browser open operation has been
triggered, it just executes next statement b.close. But it should not be
the case right? Because it has to wait until browser gets opened and
then it has to go to the next statement, So it could calculate the time
taken by the browser to open and if it exceeds the time limit ,then it
can direct the execution control inside
“rescue Timeout::Error
puts “Page load timed out”
return false”
So Is it a wrong program for Timeout, Or did i misunderstand?
RAJ
Timeout.timeout(10) do
b = Watir::Browser.new
b.goto(‘www.purple.com’)
b.close
end
I tried this code it is not giving any output, means it is not loading
loading anything. Do i need to make a call? could you please write the
full code?
Raj
You need to require ‘timeout’
ok ok.
Raj
hi Joel P.,
$browser.text_fields.each {|el| puts el.id }
hi, you have given me to print the id of the text box, but what if i
want to print the id’s of all field?(including combo,checkbox)?
What should I do?
OK, Thank you.
hi Joel P.,
I have one text box, another one is combo box, combo box value will be
populated according to the value of text box. But last focus control is
being operated here, when we come out of text box, then only combo box
is populated, So when i write the code to click the combo box, it fails
to load, So what is your suggestion in such a case?
RAJ
You could try “elements” but that’ll be quite slow on most pages since
there are often a lot you can’t see. You’re better off specifying the
type you want, e.g. select_lists, checkboxes
Try reading the documentation to see the different element types:
http://www.rubydoc.info/github/jarib/watir-webdriver/Watir/Element
Here’s something I did to deal with a dynamically updating text field.
The user clicks outside the field (or tabs away from it) after
populating it and it populates other fields automatically. This code
waits for that to happen.
You should be able to do something similar in your code for your
particular case.
@driver.text_field(:id => ‘currentcustomer’).set @data[:Account]
until @driver.text_field(:id => ‘customer_account_num’).value != ‘’
@driver.text_field(:id => ‘currentcustomer’).send_keys :tab
sleep 0.5
end
hi Joel P.
can i check whether it is text box or combo box or check box using id?
RAJ
Oh,that’s great. I solved my problem indeed.
Thanks,
RAJ
I think your best best is to use my_element.html and extract the valid
information from there.
Then how can I verify whether it is combo or text box?
for an example,
$browser.elements.each do |i|
puts i
end
Now how can i verify i is a text box or combo box, Because i need to
write a condition according to that.
Or is there any way can we print like
textbox,
combobox,
checkbox,
?
I mean I want to print the object of that screen,is it possible?
Raj
[:text_fields, :select_lists, :checkboxes].each do |type|
$browser.send(type).each do |i|
puts i, type.to_s[0…-2]
end
end
Joel P. wrote in post #1101394:
[:text_fields, :select_lists, :checkboxes].each do |type|
$browser.send(type).each do |i|
puts i, type.to_s[0…-2]
end
end
bollocks, that puts “checkboxe” instead of “checkbox”.
Ah well, you get the idea.