Class AlertActions
java.lang.Object
com.shaft.driver.internal.FluentWebDriverAction
com.shaft.gui.element.AlertActions
Provides actions for interacting with browser alert, confirm, and prompt dialogs.
AlertActions extends FluentWebDriverAction and exposes a fluent API
for accepting or dismissing alerts, reading alert text, and typing into prompt dialogs.
Every constructor automatically waits for an alert to be present before returning,
so any subsequent action is guaranteed to operate on a live dialog.
Example usage:
driver.alert().acceptAlert();
driver.alert().typeIntoPromptAlert("my input").acceptAlert();
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newAlertActionsinstance using the currently active SHAFT-managed driver.AlertActions(DriverFactoryHelper helper) Creates a newAlertActionsinstance using an existingDriverFactoryHelper.AlertActions(org.openqa.selenium.WebDriver driver) Creates a newAlertActionsinstance wrapping the providedWebDriver. -
Method Summary
Modifier and TypeMethodDescriptionAccepts (clicks "OK" on) the currently displayed alert, confirm, or prompt dialog.Dismisses (clicks "Cancel" on) the currently displayed alert or confirm dialog.Retrieves the text message displayed in the currently active browser alert dialog.booleanChecks whether a browser alert dialog is currently present.typeIntoPromptAlert(String text) Types the specified text into a JavaScript prompt dialog's input field.Methods inherited from class FluentWebDriverAction
alert, and, browser, element, initialize, initialize, initialize, initialize, performAlertAction, performBrowserAction, performElementAction, performTouchAction, touch
-
Constructor Details
-
AlertActions
public AlertActions()Creates a newAlertActionsinstance using the currently active SHAFT-managed driver. Waits for an alert to be present before returning.Example:
AlertActions alert = new AlertActions(); alert.acceptAlert(); -
AlertActions
public AlertActions(org.openqa.selenium.WebDriver driver) Creates a newAlertActionsinstance wrapping the providedWebDriver. Waits for an alert to be present before returning.Example:
AlertActions alert = new AlertActions(webDriver); alert.dismissAlert();- Parameters:
driver- theWebDriverinstance whose current window will be used to interact with the alert
-
AlertActions
Creates a newAlertActionsinstance using an existingDriverFactoryHelper. Waits for an alert to be present before returning.Example:
AlertActions alert = new AlertActions(driverFactoryHelper); alert.acceptAlert();- Parameters:
helper- theDriverFactoryHelperthat provides the underlying driver and session configuration
-
-
Method Details
-
isAlertPresent
public boolean isAlertPresent()Checks whether a browser alert dialog is currently present.Example:
if (driver.alert().isAlertPresent()) { driver.alert().acceptAlert(); }- Returns:
trueif an alert is present and reachable;falseotherwise
-
acceptAlert
Accepts (clicks "OK" on) the currently displayed alert, confirm, or prompt dialog. If no alert is present, the action is recorded as a failure.Example:
driver.alert().acceptAlert();- Returns:
- this
AlertActionsinstance for fluent method chaining
-
dismissAlert
Dismisses (clicks "Cancel" on) the currently displayed alert or confirm dialog. If no alert is present, the action is recorded as a failure.Example:
driver.alert().dismissAlert();- Returns:
- this
AlertActionsinstance for fluent method chaining
-
getAlertText
Retrieves the text message displayed in the currently active browser alert dialog.Example:
String message = driver.alert().getAlertText();- Returns:
- the alert message text, or
nullif the alert is not present or an error occurs while retrieving the text
-
typeIntoPromptAlert
Types the specified text into a JavaScript prompt dialog's input field. The prompt must already be present; callacceptAlert()afterwards to submit it.Example:
driver.alert().typeIntoPromptAlert("myValue").acceptAlert();- Parameters:
text- the text to send to the prompt dialog's input field; must not benull- Returns:
- this
AlertActionsinstance for fluent method chaining
-