Managing Windows in an Automation Script

Here, we'll be creating an automation script that manages windows. The steps for completion of this process are as follows:

  1. Review and analyze the structure of the https://trainingbypackt.github.io/Beginning-Selenium/lesson_2/exercise02_concept_05.html file.
  2. Create a new Java file for the automation script using IntelliJ IDEA. Make sure that you include the required libraries for the script to work.
  3. Using the driver.getWindowHandle() method, save the handle of the parent window in a String variable:
String parentWindowHandle = driver.getWindowHandle();

  1. Using the driver.switchTo().window(""); method, switch the focus to the TwitterWindow:
driver.switchTo().window("TwiterWindow");
  1. With the focus on "TwitterWindow", use the driver.getTitle() method to verify that the title of the page is Frame Twitter:
if (driver.getTitle().equalsIgnoreCase("Frame Twitter"))
  1. Using the System.out.println method, display a message that indicates whether the focus is on the TwitterWindow:
{
System.out.println("The script worked, the
window title is Frame Twitter");
} else {
System.out.println("Something went wrong,
the window title is NOT Frame Twitter");
}
  1. Using the driver.close() method, close "TwitterWindow":
driver.close();
  1. Return the focus to the parent window by using the windowHandle that you received on step 1.
  2. With the focus on the parent window, use the driver.getTitle() method to verify that the title of the page is Lesson 2.
  3. Compile and run the script.

You should now have a better understanding of how to navigate, resize, and switch between windows, and also how to handle different interactions with alerts.

..................Content has been hidden....................

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