Creating a Custom Wait (Waiting for an Element's Visibility)

Based on the explanation of this concept, we'll create a test with a custom wait for this web page. The aim is to implement a custom wait (waiting for an element's visibility) for this web page. Consider the following web page at https://github.com/TrainingByPackt/Beginning-Selenium/blob/master/docs/lesson_5/exercise_5_3.html:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Waiting for an element visibility</title>
</head>

<body>
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto
text-center">
<h1 class="display-4" id="lesson">Lesson 5, Exercise 3
(Pricing)</h1>
<h5 class="lead" id="instruction">Click on the button to
start a custom wait test</h5>
</div>

<div class="container">
<div class="card-deck mb-3 text-center">
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Waiting for: </h4>
//[…]

The steps for completion are as follows:

  1. Review and analyze the DOM of the https://trainingbypackt.github.io/Beginning-Selenium/lesson_5/exercise_5_3.html file, and see how elements are affected by the functionality of this file.
  2. Create a Selenium test that clicks on the button that's available:
driver.findElement(By.id("runTestButton")).click();
  1. Choose an element whose visibility changes after clicking on the test button. Create a custom wait related to that element:
WebDriverWait wait = new WebDriverWait(driver, 5);

wait.until(ExpectedConditions.
titleContains("Explicit"));
  1. Check the contents of the element's texts (as we did in the previous activities).
if (driver.getTitle().startsWith("Explicit")) {

System.out.println("ExplicitWait worked,
the element contains 'Explicit'");

} else {

System.out.println("Something went wrong
with ExplicitWait, 'Explicit' was not found");
}
  1. Compile and run the test.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.147.124