MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Alert

Class Alert

javascript/selenium-webdriver/lib/webdriver.js:3290–3347  ·  view source on GitHub ↗

* Represents a modal dialog such as alert, confirm, or * prompt. Provides functions to retrieve the message displayed with * the alert, accept or dismiss the alert, and set the response text (in the * case of prompt).

Source from the content-addressed store, hash-verified

3288 * case of {@code prompt}).
3289 */
3290class Alert {
3291 /**
3292 * @param {!WebDriver} driver The driver controlling the browser this alert
3293 * is attached to.
3294 * @param {string} text The message text displayed with this alert.
3295 */
3296 constructor(driver, text) {
3297 /** @private {!WebDriver} */
3298 this.driver_ = driver
3299
3300 /** @private {!Promise<string>} */
3301 this.text_ = Promise.resolve(text)
3302 }
3303
3304 /**
3305 * Retrieves the message text displayed with this alert. For instance, if the
3306 * alert were opened with alert("hello"), then this would return "hello".
3307 *
3308 * @return {!Promise<string>} A promise that will be
3309 * resolved to the text displayed with this alert.
3310 */
3311 getText() {
3312 return this.text_
3313 }
3314
3315 /**
3316 * Accepts this alert.
3317 *
3318 * @return {!Promise<void>} A promise that will be resolved
3319 * when this command has completed.
3320 */
3321 accept() {
3322 return this.driver_.execute(new command.Command(command.Name.ACCEPT_ALERT))
3323 }
3324
3325 /**
3326 * Dismisses this alert.
3327 *
3328 * @return {!Promise<void>} A promise that will be resolved
3329 * when this command has completed.
3330 */
3331 dismiss() {
3332 return this.driver_.execute(new command.Command(command.Name.DISMISS_ALERT))
3333 }
3334
3335 /**
3336 * Sets the response text on this alert. This command will return an error if
3337 * the underlying alert does not support response text (e.g. window.alert and
3338 * window.confirm).
3339 *
3340 * @param {string} text The text to set.
3341 * @return {!Promise<void>} A promise that will be resolved
3342 * when this command has completed.
3343 */
3344 sendKeys(text) {
3345 return this.driver_.execute(new command.Command(command.Name.SET_ALERT_TEXT).setParameter('text', text))
3346 }
3347}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected