Managing Alerts

Web applications can include pop-up alerts (modal dialogs) during any part of the process. These alerts can be of the following three types:

  • A simple alert that will show a message and expect the user to click on a button to continue an ongoing process
  •  A confirmation alert that will show a message and expect the user to accept or dismiss the alert before continuing with an ongoing process
  • A prompt alert that will show a message and expect the user to put a value in before continuing with an ongoing process

The WebDriver class, combined with the WebDriver.TargetLocator and Alert interfaces, allows automation scripts to handle the different these types of alerts. The WebDriver.TargetLocator switchTo() method is used to select a frame or a
window.

The WebDriver.TargetLocator interface provides the following methods to manage frames or windows:

  • activeElement(): Switches to the element that currently has the focus
  • alert(): Switches to the active modal dialog
  • defaultContent(): Selects either the first frame on the page, or the main document when a page contains iframes
  • frame(int index): Selects a frame by its (zero-based) index
  • frame(String nameOrID): Selects a frame by its name or ID
  • frame(WebElement frameElement): Selects a frame if its corresponding WebElement was previously located
  • parentFrame(): Changes the focus to the parent context
  • window(String nameOrHandle): Switches the focus to a window, by its name or handle

The Alert interface provides the following methods to manage modal dialogs:

  • accept(): Equivalent to clicking on the Accept button on a modal dialog
  • dismiss(): Equivalent to clicking on the Cancel button on a modal dialog
  • getText(): Gets the text of a modal dialog
  • sendKeys(String keysToSend): Sends specific keys to the modal dialog (used when the modal dialog requires the user to input data)
..................Content has been hidden....................

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