Best Selenium code snippet using Selenium.WebDriver.current_url
helpers.rb
Source:helpers.rb
...217 end218 219 def wait_for_results_list()220 wait = Selenium::WebDriver::Wait.new(:timeout => 10)221 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for search for logout #{driver.current_url} view #{@view} and tab #{@tab}.") {222 wait.until {223 begin224 results_list225 true226 rescue Selenium::WebDriver::Error::NoSuchElementError => e227 false228 end229 }230 }231 end232 233 # Return the array of results list items234 def results_list_items()235 results_list.all(".result")236 end237 238 # Return the specified results list item. Default to the first item239 def results_list_item(index=0)240 results_list_items[index]241 end242 243 # Return an array of Primo add to eshelf checkboxes244 def add_to_eshelf_checkboxes()245 driver.find_elements(:css, ".save_record input.tsetse_generated")246 end247 248 # Return the specified Primo add to eshelf checkbox. Default to the first checkbox.249 def add_to_eshelf_checkbox(index=0)250 add_to_eshelf_checkboxes[index]251 end252 253 # Return an array of Primo details link elements254 def details_links()255 results_list.find_elements(:css, ".fulldetails a")256 end257 258 # Return the specified Primo details link. Default to the first checkbox.259 def details_link(index=0)260 details_links[index]261 end262 263 # Return the list of Primo title strings264 def record_titles()265 titles = []266 driver.find_elements(:css, ".entree h2.title").each do |title|267 titles << title.text268 end269 return titles270 end271 272 # Return the specified Primo title string. Default to the first title.273 def record_title(index=0)274 record_titles[index]275 end276 277 # Return the list of e-shelf title strings278 def eshelf_titles()279 titles = []280 driver.find_elements(:css, '.entree h2.title').each do |title|281 titles << title.text282 end283 return titles284 end285 286 # Return the specified e-shelf title string. Default to the first title.287 def eshelf_title(index=0)288 eshelf_titles[index]289 end290 291 def wait_for_sidebar()292 wait = Selenium::WebDriver::Wait.new(:timeout => 10)293 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for search field for url #{driver.current_url} view #{@view} and tab #{@tab}.") {294 wait.until {295 begin296 sidebar297 true298 rescue Selenium::WebDriver::Error::NoSuchElementError => e299 false300 end301 }302 }303 end304 305 # Wait for the search field to display306 def wait_for_search_field()307 wait = Selenium::WebDriver::Wait.new(:timeout => 10)308 wait.until {309 begin310 search_field311 true312 rescue Selenium::WebDriver::Error::NoSuchElementError => e313 false314 end315 }316 end317 318 # Wait for the search for the 'search_term' to complete319 def wait_for_search(search_term)320 wait = Selenium::WebDriver::Wait.new(:timeout => 10)321 wait.until {322 begin323 search_field324 driver.title.eql?("BobCat - #{search_term}")325 rescue Selenium::WebDriver::Error::NoSuchElementError => e326 false327 end328 }329 end330 331 # Wait for the full details page for the given 'title' to render332 def wait_for_details(title)333 wait = Selenium::WebDriver::Wait.new(:timeout => 10)334 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for details for url #{driver.current_url} view #{@view} and tab #{@tab}.") {335 wait.until {336 driver.title.eql?("BobCat - #{title}")337 }338 }339 end340 341 # Wait for the email modal to display. Generally Primo::Helpers#click_email_link should be used instead342 def wait_for_email_modal()343 wait = Selenium::WebDriver::Wait.new(:timeout => 10)344 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for email modal for url #{driver.current_url} view #{@view} and tab #{@tab}.") {345 wait.until {346 begin347 driver.find_element(:css, ".ui-dialog .ui-dialog-content form#mailFormId")348 true349 rescue Selenium::WebDriver::Error::NoSuchElementError => e350 false351 end352 }353 }354 end355 356 # Wait for the email to send. Generally Primo::Helpers#send_email should be used instead357 def wait_for_email_send()358 wait = Selenium::WebDriver::Wait.new(:timeout => 10)359 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for email to send for url #{driver.current_url} view #{@view} and tab #{@tab}.") {360 wait.until {361 begin362 email_confirmation363 true364 rescue Selenium::WebDriver::Error::NoSuchElementError => e365 false366 end367 }368 }369 end370 371 # Wait to add to the eshelf. Generally Primo::Helpers#add_to_eshelf should be used instead372 def wait_for_add_to_eshelf(index=0)373 wait = Selenium::WebDriver::Wait.new(:timeout => 10)374 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting to add to eshelf for url #{driver.current_url} view #{@view} and tab #{@tab}.") {375 wait.until {376 wait = Selenium::WebDriver::Wait.new(:timeout => 10)377 wait.until { 378 (not driver.find_elements(:css => ".save_record label.tsetse_generated")[index].text.match("^In").nil?)379 }380 }381 }382 end383 384 # Wait to add to the eshelf. Generally Primo::Helpers#add_to_eshelf should be used instead385 def wait_for_uncheck_add_to_eshelf(index=0)386 wait = Selenium::WebDriver::Wait.new(:timeout => 10)387 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting to add to eshelf for url #{driver.current_url} view #{@view} and tab #{@tab}.") {388 wait.until {389 wait = Selenium::WebDriver::Wait.new(:timeout => 10)390 wait.until { 391 (not driver.find_elements(:css => ".save_record label.tsetse_generated")[index].text.match("^Add").nil?)392 }393 }394 }395 end396 397 # Wait for the eshelf to render. Generally Primo::Helpers#click_eshelf_link should be used instead398 def wait_for_eshelf()399 wait = Selenium::WebDriver::Wait.new(:timeout => 10)400 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for eshelf for url #{driver.current_url} view #{@view} and tab #{@tab}.") {401 wait.until {402 driver.find_element(:css, "h1").text == "e-Shelf"403 }404 }405 end406 407 # Wait for pds to render. Generally Primo::Helpers#login should be used instead408 def wait_for_pds()409 wait = Selenium::WebDriver::Wait.new(:timeout => 10)410 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for pds for url #{driver.current_url} view #{@view} and tab #{@tab}.") {411 wait.until {412 driver.title.eql?("BobCat")413 }414 }415 end416 417 # Wait for shibboleth to render.418 def wait_for_shibboleth_button()419 wait = Selenium::WebDriver::Wait.new(:timeout => 10)420 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for pds for url #{driver.current_url} view #{@view} and tab #{@tab}.") {421 wait.until {422 begin423 shibboleth_button424 true425 rescue Selenium::WebDriver::Error::NoSuchElementError => e426 false427 end428 }429 }430 end431 432 # Wait for shibboleth form to render. 433 def wait_for_shibboleth_form()434 wait = Selenium::WebDriver::Wait.new(:timeout => 10)435 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for pds for url #{driver.current_url} view #{@view} and tab #{@tab}.") {436 wait.until {437 begin438 shibboleth_form439 true440 rescue Selenium::WebDriver::Error::NoSuchElementError => e441 false442 end443 }444 }445 end446 447 # Wait for login to process. Generally Primo::Helpers#login should be used instead448 def wait_for_login()449 wait = Selenium::WebDriver::Wait.new(:timeout => 10)450 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for login for url #{driver.current_url} view #{@view} and tab #{@tab}.") {451 wait.until {452 begin453 logout_element454 true455 rescue Selenium::WebDriver::Error::NoSuchElementError => e456 false457 end458 }459 }460 end461 462 # Wait for logout to process. Generally Primo::Helpers#logout should be used instead463 def wait_for_logout()464 wait = Selenium::WebDriver::Wait.new(:timeout => 10)465 assert_nothing_raised(Selenium::WebDriver::Error::TimeOutError, "Error waiting for search for logout #{driver.current_url} view #{@view} and tab #{@tab}.") {466 wait.until {467 begin468 driver.find_element(:css, ".logout > h1")469 true470 rescue Selenium::WebDriver::Error::NoSuchElementError => e471 false472 end473 }474 }475 end476 477 private478 def sort_by(sort_value)479 sort_select = Selenium::WebDriver::Support::Select.new(driver.find_element(:id, "srt"))...
neckermann_nl.rb
Source:neckermann_nl.rb
...34 retry_count = 535end36# Click search button37begin38 url = driver.current_url39 driver.find_element(:id, "st_popup_acceptButton").click40 driver.find_element(:id, "QsmListerOrFullTextSearch_/sitecore/content/eComHome/Configuration/Channels/algemeen/Pages/Home/QSM_label").click41rescue => exception42 retry_count -= 143 if retry_count > 044 driver.navigate.refresh45 retry46 else47 retval = 548 puts exception.backtrace49 puts "Died on #{url}"50 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"51 teardown(driver,screenfile,retval)52 end53ensure54 retry_count = 555end56# Click the first details button57begin58 url = driver.current_url59 driver.find_element(:xpath, "//span[@class='label']").click60rescue => exception61 retry_count -= 162 if retry_count > 063 driver.navigate.refresh64 retry65 else66 retval = 567 puts exception.backtrace68 puts "Died on #{url}"69 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"70 teardown(driver,screenfile,retval)71 end72ensure73 retry_count = 574end75url = driver.current_url76if url.include? "NadDetailPage"77#Click Book now78begin79 #url = driver.current_url80 driver.find_element(:id, "#tabBar-Prices2").click81 driver.find_element(:xpath, "//div[4]/div[2]/ul[2]/li/a").click82 driver.find_element(:id, "priceTicket-submitButton").click83rescue => exception84 retry_count -= 185 if retry_count > 086 driver.navigate.refresh87 retry88 else89 retval = 590 puts exception.backtrace91 puts "Died on #{url}"92 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"93 teardown(driver,screenfile,retval)94 end95ensure96 retry_count = 597end98else99#Click another Book now100begin101 #url = driver.current_url102 driver.find_element(:id, "calcbuttonspan_extra").click103 driver.find_element(:xpath, "//span[@class='label bookNowButton']").click104rescue => exception105 retry_count -= 1106 if retry_count > 0107 driver.navigate.refresh108 retry109 else110 retval = 5111 puts exception.backtrace112 puts "Died on #{url}"113 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"114 teardown(driver,screenfile,retval)115 end116ensure117 retry_count = 5118end119end120# Fill the passenger details121begin122 url = driver.current_url123 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_gender")).select_by :value, "Male"124 driver.find_element(:id, "TravellerDetails_1_firstName").send_keys "Luke"125 driver.find_element(:id, "TravellerDetails_1_lastName").send_keys "Skywalker"126 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_days")).select_by :text, "13"127 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_months")).select_by :text, "juni"128 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_years")).select_by :text, "1990"129 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_gender")).select_by :text, "Vrouw"130 driver.find_element(:id, "TravellerDetails_2_firstName").send_keys "Mara"131 driver.find_element(:id, "TravellerDetails_2_lastName").send_keys "Skywalker"132 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_days")).select_by :text, "25"133 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_months")).select_by :text, "apr"134 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_years")).select_by :text, "1992"135 driver.find_element(:id, "foSubmit").click136rescue => exception137 retry_count -= 1138 if retry_count > 0139 driver.navigate.refresh140 retry141 else142 retval = 5143 puts exception.backtrace144 puts "Died on #{url}"145 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"146 teardown(driver,screenfile,retval)147 end148ensure149 retry_count = 5150end151#Click Next button152begin153 url = driver.current_url154 driver.find_element(:id, "btnNext").click155rescue => exception156 retry_count -= 1157 if retry_count > 0158 driver.navigate.refresh159 retry160 else161 retval = 5162 puts exception.backtrace163 puts "Died on #{url}"164 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"165 teardown(driver,screenfile,retval)166 end167ensure168 retry_count = 5169end170# Fill the passenger details (more)171begin172 url = driver.current_url173 driver.find_element(:id, "TravellerDetails_1_street").send_keys "Rokin"174 driver.find_element(:id, "TravellerDetails_1_houseNumber").send_keys "1"175 driver.find_element(:id, "TravellerDetails_1_zipCode").send_keys "1012 KT"176 driver.find_element(:id, "TravellerDetails_1_city").send_keys "Amsterdam"177 driver.find_element(:id, "TravellerDetails_1_phoneNumber").send_keys "+31 30 2357822"178 driver.find_element(:id, "TravellerDetails_1_email1").send_keys "luke.skywalker@gmail.com"179 driver.find_element(:id, "ConfirmEmailAddress").send_keys "luke.skywalker@gmail.com"180 driver.find_element(:id, "emergencyContact").send_keys "Obiwan"181 driver.find_element(:id, "emergencyPhoneNumber").send_keys "+31 30 2357822"182 driver.find_element(:id, "toPaymentButton").click183rescue => exception184 retry_count -= 1185 if retry_count > 0186 driver.navigate.refresh187 retry188 else189 retval = 5190 puts exception.backtrace191 puts "Died on #{url}"192 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"193 teardown(driver,screenfile,retval)194 end195ensure196 retry_count = 5197end198#Click Agree to pay199begin200 url = driver.current_url201 driver.find_element(:id, "NlPayAgreement").click202 driver.find_element(:id, "defaultPaymentAgreed_label").click203rescue => exception204 retry_count -= 1205 if retry_count > 0206 driver.navigate.refresh207 retry208 else209 retval = 5210 puts exception.backtrace211 puts "Died on #{url}"212 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"213 teardown(driver,screenfile,retval)214 end...
neckermann_be.rb
Source:neckermann_be.rb
...34 retry_count = 535end36# Click search button37begin38 url = driver.current_url39 driver.find_element(:id, "QsmListerOrFullTextSearch_/sitecore/content/eComHome/Configuration/Common/Components/Redesign/SOLR/QSM_label").click40rescue => exception41 retry_count -= 142 if retry_count > 043 driver.navigate.refresh44 retry45 else46 retval = 547 puts exception.backtrace48 puts "Died on #{url}"49 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"50 teardown(driver,screenfile,retval)51 end52ensure53 retry_count = 554end55# Click the first details button56begin57 url = driver.current_url58 driver.find_element(:css, "#QsmDetailLink_1 > span.label").click59rescue => exception60 retry_count -= 161 if retry_count > 062 driver.navigate.refresh63 retry64 else65 retval = 566 puts exception.backtrace67 puts "Died on #{url}"68 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"69 teardown(driver,screenfile,retval)70 end71ensure72 retry_count = 573end74#Click Book now75begin76 url = driver.current_url77 driver.find_element(:id, "calcbuttonspan_calc").click78rescue => exception79 retry_count -= 180 if retry_count > 081 driver.navigate.refresh82 retry83 else84 retval = 585 puts exception.backtrace86 puts "Died on #{url}"87 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"88 teardown(driver,screenfile,retval)89 end90ensure91 retry_count = 592end93#Click another Book now94begin95 url = driver.current_url96 driver.find_element(:xpath, "//span[@class='label bookNowButton']").click97rescue => exception98 retry_count -= 199 if retry_count > 0100 driver.navigate.refresh101 retry102 else103 retval = 5104 puts exception.backtrace105 puts "Died on #{url}"106 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"107 teardown(driver,screenfile,retval)108 end109ensure110 retry_count = 5111end112# Fill the passenger details113begin114 url = driver.current_url115 driver.find_element(:id => "TravellerDetails_1_gender").click116 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_gender")).select_by :value, "Male"117 driver.find_element(:id, "TravellerDetails_1_firstName").send_keys "Luke"118 driver.find_element(:id, "TravellerDetails_1_lastName").send_keys "Skywalker"119 driver.find_element(:id => "TravellerDetails_1_days").click120 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_days")).select_by :value, "13"121 driver.find_element(:id => "TravellerDetails_1_months").click122 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_months")).select_by :value, "6"123 driver.find_element(:id => "TravellerDetails_1_years").click124 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_years")).select_by :value, "1990"125 driver.find_element(:id => "TravellerDetails_2_gender").click126 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_gender")).select_by :value, "Female"127 driver.find_element(:id, "TravellerDetails_2_firstName").send_keys "Mara"128 driver.find_element(:id, "TravellerDetails_2_lastName").send_keys "Skywalker"129 driver.find_element(:id => "TravellerDetails_2_days").click130 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_days")).select_by :value, "25"131 driver.find_element(:id => "TravellerDetails_2_months").click132 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_months")).select_by :value, "4"133 driver.find_element(:id => "TravellerDetails_2_years").click134 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_years")).select_by :value, "1992"135 driver.find_element(:id, "foSubmit").click136rescue => exception137 retry_count -= 1138 if retry_count > 0139 driver.navigate.refresh140 retry141 else142 retval = 5143 puts exception.backtrace144 puts "Died on #{url}"145 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"146 teardown(driver,screenfile,retval)147 end148ensure149 retry_count = 5150end151#Click Next button152begin153 url = driver.current_url154 driver.find_element(:id, "btnNext").click155 driver.find_element(:id, "optionsandextrasInsurancePopupYesBtn").click156rescue => exception157 retry_count -= 1158 if retry_count > 0159 driver.navigate.refresh160 retry161 else162 retval = 5163 puts exception.backtrace164 puts "Died on #{url}"165 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"166 teardown(driver,screenfile,retval)167 end168ensure169 retry_count = 5170end171# Fill the passenger details (more)172begin173 url = driver.current_url174 driver.find_element(:id, "TravellerDetails_1_street").send_keys "Rokin"175 driver.find_element(:id, "TravellerDetails_1_houseNumber").send_keys "1"176 driver.find_element(:id, "TravellerDetails_1_zipCode").send_keys "1012 KT"177 driver.find_element(:id, "TravellerDetails_1_city").send_keys "Amsterdam"178 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_country")).select_by :value, "NL"179 driver.find_element(:id, "TravellerDetails_1_mobilePhoneNumber").send_keys "+31 30 2357822"180 driver.find_element(:id, "TravellerDetails_1_email1").send_keys "luke.skywalker@gmail.com"181 driver.find_element(:id, "ConfirmEmailAddress").send_keys "luke.skywalker@gmail.com"182 driver.find_element(:id, "toPaymentButton").click183rescue => exception184 retry_count -= 1185 if retry_count > 0186 driver.navigate.refresh187 retry...
thomascook_be.rb
Source:thomascook_be.rb
...34 retry_count = 535end36# Click search button37begin38 url = driver.current_url39 driver.find_element(:id, "QsmListerOrFullTextSearch_/sitecore/content/eComHome/Configuration/common/Components/QSM/VelocityQsmLarge_amount").click40rescue => exception41 retry_count -= 142 if retry_count > 043 driver.navigate.refresh44 retry45 else46 retval = 547 puts exception.backtrace48 puts "Died on #{url}"49 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"50 teardown(driver,screenfile,retval)51 end52ensure53 retry_count = 554end55# Click the first details button56begin57 url = driver.current_url58 driver.find_element(:css, "#QsmDetailLink_1 > span.label").click59rescue => exception60 retry_count -= 161 if retry_count > 062 driver.navigate.refresh63 retry64 else65 retval = 566 puts exception.backtrace67 puts "Died on #{url}"68 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"69 teardown(driver,screenfile,retval)70 end71ensure72 retry_count = 573end74#Click Book now75begin76 url = driver.current_url77 driver.find_element(:id, "calcbuttonspan_calc").click78rescue => exception79 retry_count -= 180 if retry_count > 081 driver.navigate.refresh82 retry83 else84 retval = 585 puts exception.backtrace86 puts "Died on #{url}"87 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"88 teardown(driver,screenfile,retval)89 end90ensure91 retry_count = 592end93#Click another Book now94begin95 url = driver.current_url96 driver.find_element(:xpath, "//span[@class='label bookNowButton']").click97rescue => exception98 retry_count -= 199 if retry_count > 0100 driver.navigate.refresh101 retry102 else103 retval = 5104 puts exception.backtrace105 puts "Died on #{url}"106 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"107 teardown(driver,screenfile,retval)108 end109ensure110 retry_count = 5111end112# Fill the passenger details113begin114 url = driver.current_url115 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_gender")).select_by :value, "Male"116 driver.find_element(:id, "TravellerDetails_1_firstName").send_keys "Luke"117 driver.find_element(:id, "TravellerDetails_1_lastName").send_keys "Skywalker"118 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_days")).select_by :text, "13"119 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_months")).select_by :text, "juni"120 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_years")).select_by :text, "1990"121 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_gender")).select_by :text, "Vrouw"122 driver.find_element(:id, "TravellerDetails_2_firstName").send_keys "Mara"123 driver.find_element(:id, "TravellerDetails_2_lastName").send_keys "Skywalker"124 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_days")).select_by :text, "25"125 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_months")).select_by :text, "apr"126 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_2_years")).select_by :text, "1992"127 driver.find_element(:id, "foSubmit").click128rescue => exception129 retry_count -= 1130 if retry_count > 0131 driver.navigate.refresh132 retry133 else134 retval = 5135 puts exception.backtrace136 puts "Died on #{url}"137 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"138 teardown(driver,screenfile,retval)139 end140ensure141 retry_count = 5142end143#Click Next button144begin145 url = driver.current_url146 driver.find_element(:id, "btnNext").click147rescue => exception148 retry_count -= 1149 if retry_count > 0150 driver.navigate.refresh151 retry152 else153 retval = 5154 puts exception.backtrace155 puts "Died on #{url}"156 screenfile = "Fail_#{Time.now.strftime("%d.%m.%Y__%H'%M'%S")}.jpg"157 teardown(driver,screenfile,retval)158 end159ensure160 retry_count = 5161end162# Fill the passenger details (more)163begin164 url = driver.current_url165 driver.find_element(:id, "TravellerDetails_1_street").send_keys "Rokin"166 driver.find_element(:id, "TravellerDetails_1_houseNumber").send_keys "1"167 driver.find_element(:id, "TravellerDetails_1_zipCode").send_keys "1012 KT"168 driver.find_element(:id, "TravellerDetails_1_city").send_keys "Amsterdam"169 Selenium::WebDriver::Support::Select.new(driver.find_element(:id => "TravellerDetails_1_country")).select_by :value, "NL"170 driver.find_element(:id, "TravellerDetails_1_mobilePhoneNumber").send_keys "+31 30 2357822"171 driver.find_element(:id, "TravellerDetails_1_email1").send_keys "luke.skywalker@gmail.com"172 driver.find_element(:id, "ConfirmEmailAddress").send_keys "luke.skywalker@gmail.com"173 driver.find_element(:id, "toPaymentButton").click174rescue => exception175 retry_count -= 1176 if retry_count > 0177 driver.navigate.refresh178 retry...
driver.rb
Source:driver.rb
...41 end42 def title43 browser.title44 end45 def current_url46 browser.current_url47 end48 def find_xpath(selector)49 browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }50 end51 def find_css(selector)52 browser.find_elements(:css, selector).map { |node| Capybara::Selenium::Node.new(self, node) }53 end54 def wait?; true; end55 def needs_server?; true; end56 def execute_script(script)57 browser.execute_script script58 end59 def evaluate_script(script)60 browser.execute_script "return #{script}"61 end62 def save_screenshot(path, options={})63 browser.save_screenshot(path)64 end65 def reset!66 # Use instance variable directly so we avoid starting the browser just to reset the session67 if @browser68 begin @browser.manage.delete_all_cookies69 rescue Selenium::WebDriver::Error::UnhandledError70 # delete_all_cookies fails when we've previously gone71 # to about:blank, so we rescue this error and do nothing72 # instead.73 end74 @browser.navigate.to('about:blank')75 end76 end77 ##78 #79 # Webdriver supports frame name, id, index(zero-based) or {Capybara::Element} to find iframe80 #81 # @overload within_frame(index)82 # @param [Integer] index index of a frame83 # @overload within_frame(name_or_id)84 # @param [String] name_or_id name or id of a frame85 # @overload within_frame(element)86 # @param [Capybara::Node::Base] a_node frame element87 #88 def within_frame(frame_handle)89 @frame_handles[browser.window_handle] ||= []90 frame_handle = frame_handle.native if frame_handle.is_a?(Capybara::Node::Base)91 @frame_handles[browser.window_handle] << frame_handle92 a=browser.switch_to.frame(frame_handle)93 yield94 ensure95 # There doesnt appear to be any way in Webdriver to move back to a parent frame96 # other than going back to the root and then reiterating down97 @frame_handles[browser.window_handle].pop98 browser.switch_to.default_content99 @frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }100 end101 def find_window( selector )102 original_handle = browser.window_handle103 browser.window_handles.each do |handle|104 browser.switch_to.window handle105 if( selector == browser.execute_script("return window.name") ||106 browser.title.include?(selector) ||107 browser.current_url.include?(selector) ||108 (selector == handle) )109 browser.switch_to.window original_handle110 return handle111 end112 end113 raise Capybara::ElementNotFound, "Could not find a window identified by #{selector}"114 end115 def within_window(selector, &blk)116 handle = find_window( selector )117 browser.switch_to.window(handle, &blk)118 end119 def quit120 @browser.quit121 rescue Errno::ECONNREFUSED...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!