4

I wanted to know, how I can use following waits in program at which situations?

  1. driver.manage.timeouts.implicit_wait = 20
  2. driver.manage.timeouts.script_timeout = 20
  3. driver.manage.timeouts.page_load = 20

My program error is:

 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.52.0/lib/selenium/webdriver/common/wait.rb:76:in `until': timed out after 10 seconds (Unable to locate element: {"method":"xpath","selector":".//*[@id='calendar']//*[contains(@class, 'fc-slot4')]/td/div"}) (Selenium::WebDriver::Error::TimeOutError)
            from anonymouspatient.rb:61:in `<main>'

I can locate this element using IRB commands but can't find an element in selenium Webdriver using Ruby.

1
  • You'll want to modify your function to rescue the Selenium::WebDriver::Error::TimeOutError exception. Your code isn't failing to find the element, it's failing to find the element in time. Can you share some code so we can help you modify it?
    – alex
    Commented May 29, 2019 at 10:13

1 Answer 1

0

Once you have your browser object initiated, you can use those settings.

According to the docs https://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Timeouts

  1. Set the amount of time the driver should wait when searching for elements.

  2. Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.

  3. Sets the amount of time to wait for a page load to complete before throwing an error.

You can use them everywhere but if you have an element that takes more time than the default (10 seconds in your example), you can use an explicit wait like:

wait = Selenium::WebDriver::Wait.new(:timeout => 15) # timeout in seconds
element = wait.until { driver.find_element(:xpath => ".//*[@id='calendar']//*[contains(@class, 'fc-slot4')]/td/div") }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.