Hey Firoz, wait methods which can be used in Selenium Webdriver to handle AJAX calls are as follows:
- Thread.Sleep(): Thread.Sleep () suspends the current thread for the specified amount of time. In AJAX, you can never be sure about the exact wait time. So, your test will fail if the element won't show up within the wait time. Moreover, it increases the overhead because calling Thread.sleep(t) makes the current thread to be moved from the running queue to the waiting queue. After the time 't' reached, the current thread will move from the waiting queue to the ready queue, and then it takes some time to be picked by the CPU and be running.
- Implicit Wait(): This method tells webdriver to wait if the element is not available immediately, but this wait will be in place for the entire time the browser is open. So any search for the elements on the page could take the time the implicit wait is set for.
- Explicit Wait(): It is used to freeze the test execution till the time a particular condition is met or maximum time lapses.
- WebdriverWait: It can be used for any conditions. This can be achieved with WebDriverWait in combination with ExpectedCondition. The best way to wait for an element dynamically is checking for the condition every second and continuing to the next command in the script as soon as the condition is met.
- Fluent Wait: This is an implementation of the Wait interface having its timeout and polling interval. Each FluentWait instance determines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition.