MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / Alert

Class Alert

javascript/selenium-webdriver/lib/webdriver.js:3253–3310  ·  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

3251 * case of {@code prompt}).
3252 */
3253class Alert {
3254 /**
3255 * @param {!WebDriver} driver The driver controlling the browser this alert
3256 * is attached to.
3257 * @param {string} text The message text displayed with this alert.
3258 */
3259 constructor(driver, text) {
3260 /** @private {!WebDriver} */
3261 this.driver_ = driver
3262
3263 /** @private {!Promise<string>} */
3264 this.text_ = Promise.resolve(text)
3265 }
3266
3267 /**
3268 * Retrieves the message text displayed with this alert. For instance, if the
3269 * alert were opened with alert("hello"), then this would return "hello".
3270 *
3271 * @return {!Promise<string>} A promise that will be
3272 * resolved to the text displayed with this alert.
3273 */
3274 getText() {
3275 return this.text_
3276 }
3277
3278 /**
3279 * Accepts this alert.
3280 *
3281 * @return {!Promise<void>} A promise that will be resolved
3282 * when this command has completed.
3283 */
3284 accept() {
3285 return this.driver_.execute(new command.Command(command.Name.ACCEPT_ALERT))
3286 }
3287
3288 /**
3289 * Dismisses this alert.
3290 *
3291 * @return {!Promise<void>} A promise that will be resolved
3292 * when this command has completed.
3293 */
3294 dismiss() {
3295 return this.driver_.execute(new command.Command(command.Name.DISMISS_ALERT))
3296 }
3297
3298 /**
3299 * Sets the response text on this alert. This command will return an error if
3300 * the underlying alert does not support response text (e.g. window.alert and
3301 * window.confirm).
3302 *
3303 * @param {string} text The text to set.
3304 * @return {!Promise<void>} A promise that will be resolved
3305 * when this command has completed.
3306 */
3307 sendKeys(text) {
3308 return this.driver_.execute(new command.Command(command.Name.SET_ALERT_TEXT).setParameter('text', text))
3309 }
3310}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected