Activity: Resizing and Moving Windows with a Selenium Automation Script

  1. Using the driver.get() method in the ActivityLesson02 constructor, load https://www.packt.com:
driver.get("https://www.packt.com");
  1. Using the manage().window().setSize(Dimension) method, resize the current window:
driver.manage().window().setSize(new Dimension(300,500));
  1. Using the manage().window().getSize() method, verify that the size of the window is equal to the size of the one that you set in step 2:
if (driver.manage().window().getSize().getHeight() == 300
&& driver.manage().window().getSize().getWidth() == 500 )
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Load script worked, the
window was resized");
}
else {
System.out.println("Something went wrong
with the script, the window was not resized to the desired
size");
}

  1. Using the manage().window().maximize() method, maximize the current window:
driver.manage().window().maximize();
  1. Using the manage().window().getSize() method, verify that the size of the window is different from the one that you set in step 2.
if (driver.manage().window().getSize().getHeight() != 300
&& driver.manage().window().getSize().getWidth() != 500 )
driver.manage().window().maximize();
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Load script worked, the
window was resized");
}
else {
System.out.println("Something went wrong
with the script, the window was not resized");
}
  1. 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 another window:
driver.switchTo().window("TwitterWindow");
  1. Using the System.out.println method, display a message that indicates whether the focus is on the new window:
{
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 the new window:
driver.close();
  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.145.93.210