Book Image

Selenium WebDriver Quick Start Guide

By : Pinakin Chaubal
Book Image

Selenium WebDriver Quick Start Guide

By: Pinakin Chaubal

Overview of this book

Selenium WebDriver is a platform-independent API for automating the testing of both browser and mobile applications. It is also a core technology in many other browser automation tools, APIs, and frameworks. This book will guide you through the WebDriver APIs that are used in automation tests. Chapter by chapter, we will construct the building blocks of a page object model framework as you learn about the required Java and Selenium methods and terminology. The book starts with an introduction to the same-origin policy, cross-site scripting dangers, and the Document Object Model (DOM). Moving ahead, we'll learn about XPath, which allows us to select items on a page, and how to design a customized XPath. After that, we will be creating singleton patterns and drivers. Then you will learn about synchronization and handling pop-up windows. You will see how to create a factory for browsers and understand command design patterns applicable to this area. At the end of the book, we tie all this together by creating a framework and implementing multi-browser testing with Selenium Grid.
Table of Contents (10 chapters)

Handling non-modal popup windows

We will be using the website http://popuptest.com/goodpopups.html to demonstrate non-modal pop-up windows. We will write a small program to load this URL and then click the Good PopUp #1 link. A pop-up window will open and then we will fetch the window handles of both the open windows.

The following code clicks a link on the home page and fetches the window handles of both the open windows as well as their titles:

 WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("http://popuptest.com/goodpopups.html");
driver.findElement(By.xpath("//a[text()='Good PopUp #1']")).click();
Set openWindows = driver.getWindowHandles();
System.out.println("No of open windows: " + openWindows.size());
Iterator<String> it = openWindows.iterator();
String parent = it.next();
System...