Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait until particular element to disappear

Using Ruby, we can wait for particular element by doing following:

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.find_element(:class, 'gritter-item') }

but if I want particular element to disappear from DOM, I write method like:

  def disappear_element
    begin
      driver.find_element(:class, 'gritter-item')
    rescue Selenium::WebDriver::Error::NoSuchElementError
      true
    else
      false
    end
  end

and called it like:

wait.until { disappear_element }

This way I could achieve absence of element. Is there any better way in Ruby to achieve the same?

like image 623
Alpha Avatar asked Oct 15 '13 07:10

Alpha


1 Answers

You can write disappear_element as follow (using find_elements instead of find_element):

def disappear_element
  driver.find_elements(:class, 'gritter-item').size == 0
end
like image 200
falsetru Avatar answered Sep 29 '22 20:09

falsetru