Method: Selenium::WebDriver::Driver#wait_for_element
- Defined in:
- lib/oats/oats_selenium_api.rb
#wait_for_element(locators, *options) ⇒ Object
Returns Locator if found in any of the locator(s array), or raises OatsTestError Sets selenium.last_locator and selenium.last_element See Oats.wait_until for definition of options hash, Waits for options if specified
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/oats/oats_selenium_api.rb', line 438 def wait_for_element(locators, *) locators = [locators] unless locators.instance_of?(Array) wait_opts = {} while o = .shift if o.instance_of?(Hash) wait_opts = o else locators.push o end end wait_opts[:message] ||= "Could not find locator: #{locators}" extra_seconds = wait_opts.delete(:extra_seconds) if wait_opts[:extra_seconds] time = wait_opts[:seconds] ? "#{wait_opts[:seconds].to_s} seconds " : '' oats_debug "wait #{time}for #{locators}" @last_locator = nil found = nil save_debug = @no_oats_debug Oats.wait_until wait_opts do locators.find do |loc| found = element?(loc) # if webdriver? found = nil if found and not found.element.displayed? # else # begin # if found and selenium.visible?(loc) # found = loc # else # found = nil # end # rescue Selenium::CommandError => exc # found = nil unless exc.message =~ /Element .* not found/ # end # end if found and block_given? @no_oats_debug = true yield found else found end end end @no_oats_debug = save_debug oats_debug "found locator: #{found}" if found and locators.size > 1 if extra_seconds && !Oats.data('selenium.no_extra_sleep') oats_debug "is waiting #{extra_seconds} extra seconds for #{locators}" sleep extra_seconds end @last_locator = found if found return found ensure @no_oats_debug = save_debug end |