0 votes
in Selenium by
In Selenium WebDriver, how do you handle Ajax calls?

1 Answer

0 votes
by

When using Selenium WebDriver, one of the most prevalent challenges is handling AJAX calls. We would have no way of knowing when the AJAX call would complete, and the page would be refreshed. In this tutorial, we'll look at how to use Selenium to handle AJAX calls. AJAX (Asynchronous JavaScript and XML) is an acronym for Asynchronous JavaScript and XML. AJAX allows a web page to obtain little quantities of data from the server without having to completely reload the page. Without reloading the page, AJAX sends HTTP requests from the client to the server and then processes the server's answer. Wait commands may not work with AJAX controls. It's only that the page itself is not going to refresh.

The essential information may show on the web page without refreshing the browser when you click on a submit button. It may load in a fraction of a second, or it may take longer. We have no control over how long it takes for pages to load. In Selenium, the easiest way to deal with circumstances like this is to employ dynamic waits (i.e., WebDriverWait in combination with ExpectedCondition)

The following are some of the approaches that are available:

1. titleIs() – The anticipated condition looks for a specific title on a page.

wait.until(ExpectedConditions.titleIs("Big Sale of the Year"));

2. elementToBeClickable() – The desired condition requires that an element be clickable, which means that it must be present/displayed/visible on the screen and enabled.

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath")));

3. alertIsPresent() – The expected condition anticipates the appearance of an alert box.

wait.until(ExpectedConditions.alertIsPresent())!=null);

4. textToBePresentInElement() – The anticipated condition looks for a string pattern in an element.

wait.until(ExpectedConditions.textToBePresentInElement(By.id("text"),"text to be found");

Related questions

0 votes
asked Jan 9 in Selenium by sharadyadav1986
0 votes
asked Jan 9 in Selenium by sharadyadav1986
...