Book Image

Selenium Essentials

By : Prashanth Sams
Book Image

Selenium Essentials

By: Prashanth Sams

Overview of this book

Table of Contents (12 chapters)

Handling Ajax websites


Every modern web application makes use of Ajax calls that return data through asynchronous calls made to the web server. It avoids page reload and updates part of the web page at any time. Let's see how to manage these Ajax-based websites through Selenium WebDriver in detail.

The isElementPresent method

The isElementPresent() method is a user-defined method that checks for an element's availability within a web page. By default, the Selenium IDE generates the following script, where the object returns a Boolean value (however, this method is not recommended for handling Ajax-based web apps):

private boolean isElementPresent(By by) {
  try {
    driver.findElement(by);
    return true;
  } catch (NoSuchElementException e) {
    return false;
  }
}

@Test
public void Test01() throws Exception {
  driver.get("https://www.google.co.in/");
  Boolean a = isElementPresent(By.name("q"));
  System.out.println(a);
  Boolean b = isElementPresent(By.name("selenium_essentials"));...