Creating a Custom Wait (Waiting for an Element)

The aim here is to implement a custom wait (waiting for an element). Consider the following web page at https://github.com/TrainingByPackt/Beginning-Selenium/blob/master/docs/lesson_5/exercise_5_1.html:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Waiting for an element</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 1
(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_1.html file, and see how elements are affected by the functionality of this file.
  2. Create a Selenium test that clicks on the available button:
driver.findElement(By.id("runTestButton")).click();
  1. Choose any of the elements whose attribute values are changed after clicking on the test button. Create a custom wait related to the chosen element:
 WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.
titleContains("Explicit"));
  1. For each one of the instructions in step 3, check the contents of the element's texts (as we did in the previous activity):
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.
  2. You may repeat steps 3 and 4 for different objects.
..................Content has been hidden....................

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