From: "Jesús Gabriel y Galán" Date: 2011-05-22T05:09:03+09:00 Subject: Re: Looping n rows in table On Sat, May 21, 2011 at 8:08 PM, Ashok T. wrote: > Thank you Jesus for your gracious reply. > > I tried to execute using help from your ruby code. However since the > text keeps on changing, i cannot put the exact text. So i came up with > two options on the code which didn't work either. > > To answer your questions, i am using watir to automate my web app. So i > declared $b = Watir::Browser.new :chrome > > I am trying to iterate the table so it is taking $b > > Table= $b.table(:id, /grid/) > > 1 2 3 4 5 > > 2 100 2000 > > 3 150 3000 text dropdown > > 4 200 4000 > > 5 250 5000 text dropdown > > n 300 6000 > > However, i got the following error message when i used the following > code > > Table.rows.each do |row| > > row[5].select("Value from the dropdown") if row[4].text.exists? > > end > > Error > > C:/Watir Scripts/Project/Debit.rb:58:in block in report': undefined > methodexists?' for "Account Number":String (NoMethodError) from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/element_collection.rb:21:in > each' from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/element_collection.rb:21:ineach' > from C:/Watir Scripts/Project/Debit.rb:57:in report' from > driver.rb:36:inrun' from driver.rb:42:in `' > > So i tried to tweak the script and wrote as below. > > Table.rows.each do |row| > > if row[4].text!= "" > > row[5].select("Value from the dropdown") > > end > > Then i got the following error message. > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/container.rb:36:in > extract_selector': expected Hash or (:how, 'what'), got ["Exclude: > Duplicate Account"] (ArgumentError) from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/elements/generated.rb:2163:inselect' > from C:/Watir Scripts/Project/Credit.rb:53:in block in report' from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/element_collection.rb:21:ineach' > from > C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.2.3/lib/watir-webdriver/element_collection.rb:21:in > each' from C:/Watir Scripts/Project/Debit.rb:51:inreport' from > driver.rb:36:in run' from driver.rb:42:in' > > So i think we need to use (how, what) expressions, can you help me how > to use those expressions in 'each' command? I don't know much about Watir, but seeing that the error is in container.rb, I looked here: http://rdoc.info/gems/watir/1.8.1/Watir/Container:select_list There you can find information about what :how and "what" mean, and which values you can pass there. Jesus.