Interacting with Textboxes and Textareas During an Automation Script

The aim here is to create an automation script that interacts with textboxes and textareas. We will assume that the textbox/textarea element has been found by means of its ID (we will go deeper into the findElement method in an upcoming section):

WebElement textArea = driver.findElement(By.
id("aboutYourself"));

Open the https://trainingbypackt.github.io/Beginning-Selenium/lesson_3/exercise_3_1.html file and use IntelliJ IDEA for the creation of a Selenium script. 

The steps for completion of this process are as follows:

  1. Review and analyze the structure and behavior of the https://trainingbypackt.github.io/Beginning-Selenium/lesson_3/exercise_3_1.html file.
  2. Create a new Java file for the automation script. Make sure that you include the required libraries:
package com.beginningselenium.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
  1. Locate the textarea of the By.id "aboutYourself":
WebElement textArea = driver.findElement(By.
id("aboutYourself"));
  1. Verify that the textarea is enabled and visible:
if (textArea.isEnabled() && textArea.isDisplayed())
  1. Using the System.out.println method in the if loop, display messages indicating whether the verification was successful or not:
System.out.println("The text area is visible and
displayed");
else {
System.out.println("Something went wrong, the text
area is not visible and displayed");
}
  1. If the textarea is enabled and visible, verify that it is empty:
// Checking for an empty text area
if ("".equals(textArea.getAttribute("value")))

Have the code of steps 6-11 inside the if (textArea.isEnabled() && textArea.isDisplayed()) loop.
  1. Using the System.out.println method, display messages indicating whether the verification was successful or not:
{
System.out.println("The text area is empty");
} else {
System.out.println("Something is wrong, the text
area NOT empty");
}
  1. Input some text and then verify that the text was actually typed:
textArea.sendKeys("This is a sample text.");
if ("This is a sample text.".equals(textArea.
getAttribute("value")))
  1. Using the System.out.println method, display messages indicating whether the verification was successful or not and that the name was sent.
{
System.out.println("Text was correctly typed into
the text area.");
} else {
System.out.println("Something went wrong, text
was not typed into the text area.");
}
  1. Clear the textarea contents and verify that it is empty:
textArea.clear();
if ("".equals(textArea.getAttribute("value")))
  1. Using the System.out.println method, display messages indicating whether the verification was successful or not and that the name was sent:
{
System.out.println("The text area is empty after
cleaning it though a Selenium command");
} else {
System.out.println("Something went wrong, the
text area was not cleaned");
}
  1. Compile and run the script.
..................Content has been hidden....................

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