I wanted to know, how I can use following waits in program at which situations?
driver.manage.timeouts.implicit_wait = 20
driver.manage.timeouts.script_timeout = 20
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.
-
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– alex2019年05月29日 10:13:12 +00:00Commented May 29, 2019 at 10:13
1 Answer 1
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
Set the amount of time the driver should wait when searching for elements.
Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.
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") }
Explore related questions
See similar questions with these tags.