[wtr-general] Re: Any fast ways to parse a table
The "CheckTableUsingRowArray" approach does not seem faster to me. The location of the timer excludes the Watir portion of the code, which is costly. In particular, the following line adds about 28 seconds for me: myTableArray = obj.to_a #Array the table An alternative approach is to use the Nokogiri gem to parse the table. Zeljko had a good post on the topic - http://zeljkofilipin.com/watir-nokogiri/ . Try the following, which takes about 0.1 seconds: #myHash is the same ordered hash used in the other approaches: myHash = { 'col1' => 'Row30 Content1', 'col2' => 'Row30 Content2', 'col3' => 'Row30 Content3', 'col4' => 'Row30 Content4', 'col5' => 'Row30 Content5', 'col6' => 'Row30 Content6', 'col7' => 'Row30 Content7', 'col8' => 'Row30 Content8' } myArray = myHash.values start = Time.now obj = ie.table(:id,'table1') nokogiri = Nokogiri::HTML.parse(obj.html) nokogiri.css('tr').each_with_index do |tr, i| if tr.css('td').collect(&:text) == myArray puts "Row to click: #{i}" end end puts "Time to finish: #{Time.now - start}" #Output: # Row to click 30 # Time to finish: 0.091 - Justin Ko On Friday, July 12, 2013 5:49:07 PM UTC-4, Super Kevy wrote: > > OK. I ran a sample and have some benchmarks for a simple table look up > > In the sample below I have a simple table with 30 row of 8 columns. > The test measure the time to find the matching row (the sample is row 30) > There are two methods. One uses if comparisons of the tables columns > within the row. The second method intersects the data to find with an array > of each row. The time was quite dramatic. > > Using the If statements the time was about 25 seconds to find matching > table row 30 > Using the intersect method for arrray comparisons the table match was > immediate (zero seconds) > > Script Code > === > require 'rubygems' > require 'watir-webdriver' > #require 'win32ole' > require 'uri' > require 'date' > > def Method_OpenBrowser(sURL,sBrowserType) > puts '* Method_OpenBrowser' > puts ' - Browser type: ' + sBrowserType.to_s > puts ' - URL: ' + sURL.to_s > ie=0 > ie = Watir::Browser.new(sBrowserType) > ie.window.maximize() > ie.goto(sURL) > sleep 2 > puts ' - Return ' + ie.to_s > return ie > end > > # > # Hash values are fetched and compared using ifs with each row column > # A complete match outputs the time delta > # > def Method_CheckTableUsingIfs(ie,myHash) > puts '* Method_CheckTableUsingIfs' > puts ' - # of Column values to match: ' + myHash.length().to_s > obj = ie.table(:id,'table1').tbody(:id,'tbody1') > iDataRows = obj.rows.length() - 1 > iRowIndex = 1 > startTime = Time.now > iDataRows.times do > if myHash.fetch('col1') == obj.tr(:index => iRowIndex).td(:index => > 0).text.to_s then > if myHash.fetch('col2') == obj.tr(:index => iRowIndex).td(:index => > 1).text.to_s then > if myHash.fetch('col3') == obj.tr(:index => iRowIndex).td(:index > => 2).text.to_s then > if myHash.fetch('col4') == obj.tr(:index => > iRowIndex).td(:index => 3).text.to_s then > if myHash.fetch('col5') == obj.tr(:index => > iRowIndex).td(:index => 4).text.to_s then > if myHash.fetch('col6') == obj.tr(:index => > iRowIndex).td(:index => 5).text.to_s then > if myHash.fetch('col7') == obj.tr(:index => > iRowIndex).td(:index => 6).text.to_s then > if myHash.fetch('col8') == obj.tr(:index => > iRowIndex).td(:index => 7).text.to_s then > puts ' - All columns matched. Return the delta time to > main. Click this row: ' + iRowIndex.to_s > endTime = Time.now - startTime > puts ' - Time to match: ' + endTime.to_s > puts ' - Return: ' + endTime.to_s > STDOUT.flush() > return endTime.to_s > end > end > end > end > end > end > end > end > iRowIndex = iRowIndex + 1 > end > puts ' - No Match in table. ' > puts ' - Return: -1' > return -1 > end > > > # > # The Hash is converted to an array (array = hash.values). > # The array is matched using intersection of the table's row array > # A complete match outputs the time delta > # > def Method_CheckTableUsingRowArray(ie,myArray) > puts '* Method_CheckTableUsingRowArray' > puts ' - # of Column values to match: ' + myArray.length().to_s > obj = ie.table(:id,'table1').tbody(:id,'tbody1') > myTableArray = obj.to_a #Array the table > puts ' - Table Length (Rows): ' + myTableArray.length().to_s > iRowIndex=0 > startTime
[wtr-general] Re: Any fast ways to parse a table
OK. I ran a sample and have some benchmarks for a simple table look up In the sample below I have a simple table with 30 row of 8 columns. The test measure the time to find the matching row (the sample is row 30) There are two methods. One uses if comparisons of the tables columns within the row. The second method intersects the data to find with an array of each row. The time was quite dramatic. Using the If statements the time was about 25 seconds to find matching table row 30 Using the intersect method for arrray comparisons the table match was immediate (zero seconds) Script Code === require 'rubygems' require 'watir-webdriver' #require 'win32ole' require 'uri' require 'date' def Method_OpenBrowser(sURL,sBrowserType) puts '* Method_OpenBrowser' puts ' - Browser type: ' + sBrowserType.to_s puts ' - URL: ' + sURL.to_s ie=0 ie = Watir::Browser.new(sBrowserType) ie.window.maximize() ie.goto(sURL) sleep 2 puts ' - Return ' + ie.to_s return ie end # # Hash values are fetched and compared using ifs with each row column # A complete match outputs the time delta # def Method_CheckTableUsingIfs(ie,myHash) puts '* Method_CheckTableUsingIfs' puts ' - # of Column values to match: ' + myHash.length().to_s obj = ie.table(:id,'table1').tbody(:id,'tbody1') iDataRows = obj.rows.length() - 1 iRowIndex = 1 startTime = Time.now iDataRows.times do if myHash.fetch('col1') == obj.tr(:index => iRowIndex).td(:index => 0).text.to_s then if myHash.fetch('col2') == obj.tr(:index => iRowIndex).td(:index => 1).text.to_s then if myHash.fetch('col3') == obj.tr(:index => iRowIndex).td(:index => 2).text.to_s then if myHash.fetch('col4') == obj.tr(:index => iRowIndex).td(:index => 3).text.to_s then if myHash.fetch('col5') == obj.tr(:index => iRowIndex).td(:index => 4).text.to_s then if myHash.fetch('col6') == obj.tr(:index => iRowIndex).td(:index => 5).text.to_s then if myHash.fetch('col7') == obj.tr(:index => iRowIndex).td(:index => 6).text.to_s then if myHash.fetch('col8') == obj.tr(:index => iRowIndex).td(:index => 7).text.to_s then puts ' - All columns matched. Return the delta time to main. Click this row: ' + iRowIndex.to_s endTime = Time.now - startTime puts ' - Time to match: ' + endTime.to_s puts ' - Return: ' + endTime.to_s STDOUT.flush() return endTime.to_s end end end end end end end end iRowIndex = iRowIndex + 1 end puts ' - No Match in table. ' puts ' - Return: -1' return -1 end # # The Hash is converted to an array (array = hash.values). # The array is matched using intersection of the table's row array # A complete match outputs the time delta # def Method_CheckTableUsingRowArray(ie,myArray) puts '* Method_CheckTableUsingRowArray' puts ' - # of Column values to match: ' + myArray.length().to_s obj = ie.table(:id,'table1').tbody(:id,'tbody1') myTableArray = obj.to_a #Array the table puts ' - Table Length (Rows): ' + myTableArray.length().to_s iRowIndex=0 startTime = Time.now myTableArray.each do |e| case (e & myArray).length() when 8 puts ' - All columns matched. Return the delta time to main. Click this row: ' + iRowIndex.to_s endTime = Time.now - startTime puts ' - Time to match: ' + endTime.to_s puts ' - Return: ' + endTime.to_s STDOUT.flush() return endTime.to_s else # do nothing end iRowIndex=iRowIndex+1 end puts ' - No Match in table. ' puts ' - Return: -1' return -1 end ### # Main ### # Make some data to use ie=0 sBrowserType = :chrome #symbolic # Localize and encode the html test url puts ' Current Dir: ' + Dir.getwd.to_s sURL = "file:///" + URI.escape(Dir.getwd) + '/columns.html' myHash = { 'col1' => 'Row30 Content1', 'col2' => 'Row30 Content2', 'col3' => 'Row30 Content3', 'col4' => 'Row30 Content4', 'col5' => 'Row30 Content5', 'col6' => 'Row30 Content6', 'col7' => 'Row30 Content7', 'col8' => 'Row30 Content8' } # Display some messages puts 'Check Speed Of Table Parse' puts ' - Test URL: ' + sURL.to_s puts ' - Browser type: ' + sBrowserType.to_s STDOUT.flush # Begin the test ie = Method_OpenBrowser(sURL,sBrowserType) Method_CheckTableUsingIfs(ie,myHash) Method_CheckTable
Re: [wtr-general] Possible element.click bug
Driving IE 10 (Browser Mode: IE10 Compat View, Document Mode: IE7 Standards) Windows 7 Starting browser with Watir::Browser.start(url, :ie) Thanks, -Mont -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [wtr-general] [Watir-WebDriver] Wait until the text-field values are fetched through API
I'm not 100% sure what it's doing but you probably need to poll for some condition after 'lookup' so that it knows lookup is done before continuing. Maybe something like this Watir::Wait.until(60) do br.text =~ /some regexp check/ end From: maulik goswami To: watir-general@googlegroups.com Sent: Friday, July 12, 2013 1:58 AM Subject: [wtr-general] [Watir-WebDriver] Wait until the text-field values are fetched through API I am writing the registration script where the API is being called in company registration no field which fetches all the data regarding company and fill it automatically in according text-field like name, phone no, address etc. So i want to make the script wait until all text-field vales are filled with values. I have tried the following script but it doesn't wait and clicks on continue button before all the values are fetched. require "watir-webdriver" require "watir-webdriver/wait" br = Watir::Browser.new :chrome br.goto verification_link br.a(:text => "Continue Manually").click br.text_field(:id => "regNumber").set "03977902" br.button(:id => "populatebtn").click Watir::Wait.until(10) {br.text_field(:id => "companyName").value.exists?} br.select_list(:id => "companyType").select("Limited") br.select_list(:id => "nature").select("Art") br.text_field(:id => "sales_turnover").set "12000" br.select_list(:id => "why").select("Bill Payment") br.button(:id => "lookup").click br.button(:id => "continue").click -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [wtr-general] [Watir-WebDriver] Wait until the text-field values are fetched through API
On Fri, Jul 12, 2013 at 10:58 AM, maulik goswami wrote: > Watir::Wait.until(10) {br.text_field(:id => "companyName").value.exists?} I think the problem is that here you are waiting for the text field to have any value, and I guess empty string is any value. You should probably wait until the text field's value is different from empty string, or something like that. Željko -- https://leanpub.com/watirbook -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[wtr-general] [Watir-WebDriver] Wait until the text-field values are fetched through API
I am writing the registration script where the API is being called in company registration no field which fetches all the data regarding company and fill it automatically in according text-field like name, phone no, address etc. So i want to make the script wait until all text-field vales are filled with values. I have tried the following script but it doesn't wait and clicks on continue button before all the values are fetched. require "watir-webdriver" require "watir-webdriver/wait" br = Watir::Browser.new :chrome br.goto verification_link br.a(:text => "Continue Manually").click br.text_field(:id => "regNumber").set "03977902" br.button(:id => "populatebtn").click Watir::Wait.until(10) {br.text_field(:id => "companyName").value.exists?} br.select_list(:id => "companyType").select("Limited") br.select_list(:id => "nature").select("Art") br.text_field(:id => "sales_turnover").set "12000" br.select_list(:id => "why").select("Bill Payment") br.button(:id => "lookup").click br.button(:id => "continue").click -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[wtr-general] Re: [Watir-Webdriver] How can i access Gmail
Thanks for you help Roman, i got similar solution for it through * Stakeoverflow* verification_link = ''Gmail.new("sam...@registration.com", "11") do |gmail|email = gmail.inbox.emails(:unread, :from => 'nore...@registration.com').first message = email.body.decodedverification_link = /Verify Now<\/a>/m.match(message)[1].gsub(/\s/, '')end On Thursday, 11 July 2013 19:15:46 UTC+5:30, Roman Rodriguez wrote: > > It's not a Watir issue. It's about use of Gmail gem on ruby script. I > think you could try something like this: > > email = gmail.inbox.find(*:unread, :from => "no reply registration email"* > ).*label("Confirm Verification")* > email_text = email.message.html_part.body.to_s > url_start = email_text.index('http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [wtr-general] Possible element.click bug
On Thu, Jul 11, 2013 at 9:58 PM, Mont Rothstein wrote: > If someone can verify this is a bug I'd be happy to submit it. Feel free to submit a bug even before somebody else confirms it. > Also, I don't know if this would be a Watir bug or a Watir-WebDriver bug. I can help to figure that out. What browser are you driving? What OS are you on? How do you start the browser? Željko -- https://leanpub.com/watirbook -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[wtr-general] Possible element.click bug
I've found what I believe is a bug in element.click but it is strange and inconsistent so I am uncertain. The general issue is clicking menu items in a CSS drop-down menu. The specific problem is that for some menu items, specifically and only the first item under the first and third top-level menu, the click event causes the first item on the next menu over to be clicked. Ex: an attempt to send a click to Menu1->MenuItem1 in fact clicks Menu2->MenuItem1. Here are Watir examples using the HTML and CSS at the end of this message. This works (Menu2->MenuItem1): $b.li(:id,'ctl00_ChangeCustodyMenu').hover $b.li(:id, 'ctl00_CheckInMenuItem').click The second also line can also be either of: $b.li(:text, 'Check In').click $b.link(:text,'Check In').click This does not work. Instead of clicking Menu1->MenutItem1 it clicks Menu2->MenuItem1 $b.li(:id,'ctl00_AddMenu').hover $b.li(:id, 'ctl00_AddAssetFolderMenuItem').click Also does not work. Instead of clicking Menu3->MenutItem1 it clicks Menu4->MenuItem1 $b.li(:id,'ctl00__actionsMenu').hover $b.li(:id, 'ctl00_moveItemsMenuItem').click All menu items 2-N for all menus work fine on any menu. Only the first item for the 1st and 3rd menus don't work. I have found a work around. Calling the OnClick fire event specifically on the anchor element seems to do the trick. $b.li(:id,'ctl00__actionsMenu').hover $b.link(:text,'Move Items').fire_event('onClick') If someone can verify this is a bug I'd be happy to submit it. Also, I don't know if this would be a Watir bug or a Watir-WebDriver bug. Thanks, -Mont P.S. I am brand new to both Watir and Ruby. The HTML source is: Add Folder Change Custody Check In Check Out Drop-off Actions Move Items Process Audit View/Edit Audit Results Change Owner Reports Analysis Requested Asset Details The associated CSS is: .menuBarButtons { margin-left: 10px; display: inline; white-space: nowrap; } .menu { position:relative; z-index:12; } /* remove all the bullets, borders and padding from the default list styling */ .menu ul { padding:0; margin:0; list-style-type:none; } /* float the list to make it horizontal and a relative positon so that you can control the dropdown menu positon */ .menu li { float:left; position:relative; color: #f8eeac; padding-left: 5px; padding-right: 5px; } .menu li:hover { color: #8fc5d9; } /* style the links for the top level */ .menu a, .menu a:visited { display:block; text-decoration:none; border:1px solid #353535; border-width:0px 0px 0px 1px; } /* hide the sub levels and give them a positon absolute so that they take up no room */ .menu ul ul { visibility:hidden; position:absolute; height:0; top:23px; left:0px; /* Change this to right to cause the drop-downs to extend to the left instead of the right */ width:172px; /* This must be the width of the link plus the left and right padding on the link */ border-top:1px solid #000; text-align: left; } .menu ul ul li { padding-left: 0px; /* clear out inherited padding */ padding-right: 0px; /* clear out inherited padding */ } /* style the second level links */ .menu ul ul a, .menu ul ul a:visited { background:#6a6a6a; color:#FFF; height:auto; line-height:1em; padding:5px 10px 5px 10px; width:150px; /* This can be any width but must be reflected in the ".menu ul ul" width */ border-width:0 1px 1px 1px; } /* style the second level hover */ .menu ul ul a:hover { color: black; background-color: #c0c0c0; } /* make the second level visible when hover on first level list OR link */ .menu ul li:hover ul, .menu ul a:hover ul { visibility:visible; } -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[wtr-general] Above the fold screenshots
How can I take them? -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.