public void checkAlert() { try { WebDriverWait wait = new WebDriverWait(driver, 2); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); alert.accept(); } catch (Exception e) { //exception handling } }
public String confirm(String expectedDialogText) { Alert alert = driver.switchTo().alert(); String actualDialogText = alert.getText(); alert.accept(); checkDialogText(driver, expectedDialogText, actualDialogText); return actualDialogText; }
public String prompt(String expectedDialogText, String inputText) { Alert alert = driver.switchTo().alert(); String actualDialogText = alert.getText(); if (inputText != null) alert.sendKeys(inputText); alert.accept(); checkDialogText(driver, expectedDialogText, actualDialogText); return actualDialogText; }
Alert alert = webdriver.switchTo().alert(); log.severe(e + ": " + alert.getText()); alert.accept(); savePageSourceToFile(config, fileName, webdriver, false);
protected boolean assertThatAlertListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { Alert alert = driver.switchTo().alert(); alert.accept(); alert.dismiss(); alert.sendKeys("Keys"); assertThat(listener.messages, contains(prefix + "Attempt to accept alert", prefix + "The alert was accepted", prefix + "Attempt to dismiss alert", prefix + "The alert was dismissed", prefix + "Attempt to send keys to alert", prefix + "Keys were sent to alert")); return true; } finally { listener.messages.clear(); } }
new WebDriverWait(driver, 60) .ignoring(NoAlertPresentException.class) .until(ExpectedConditions.alertIsPresent()); Alert al = driver.switchTo().alert(); al.accept();
@Test public void alertEventTest() { try { Alert alert = driver.switchTo().alert(); alert.accept(); alert.dismiss(); alert.sendKeys("Keys"); assertThat(listener.messages, hasItems(WEBDRIVER_EVENT_LISTENER + "Attempt to accept alert", WEBDRIVER_EVENT_LISTENER + "The alert was accepted", WEBDRIVER_EVENT_LISTENER + "Attempt to dismiss alert", WEBDRIVER_EVENT_LISTENER + "The alert was dismissed")); } finally { listener.messages.clear(); } }
@Test public void acceptAlertTest() { Supplier<Boolean> acceptAlert = () -> { driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click(); waiting.until(alertIsPresent()); driver.switchTo().alert().accept(); return true; }; assertTrue(acceptAlert.get()); }
try { click(myButton); } catch (UnhandledAlertException f) { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); System.out.println("Alert data: " + alertText); alert.accept(); } catch (NoAlertPresentException e) { e.printStackTrace(); } }
WebDriverWait wait = new WebDriverWait(WD, 30); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = WD.switchTo().alert(); String alertText = alert.getText(); System.out.println(alertText); alert.accept();
public void accept() { dispatcher.beforeAlertAccept(driver); alert.accept(); dispatcher.afterAlertAccept(driver); }
public void javascript_popup_click_ok() { Alert alert = get_current_alert_box(); if(alert != null) { action("Accepted the javascript popup '" + alert.getText() + "'"); alert.accept(); } }
/** * Accepts any present alert. Returns true if there is an alert to click. */ private boolean acceptAnyAlert(final WebDriver driver) { boolean hasAlert = ExpectedConditions.alertIsPresent().apply(driver) != null; if (hasAlert) { driver.switchTo().alert().accept(); log.info("** A browser alert has been accepted **"); } return hasAlert; } }
public void clickDeleteAndConfirm() { this.deleteLink.click(); Alert alert = driver.switchTo().alert(); if (alert != null) { alert.accept(); } }
@Test public void multiTouchTest() { MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); MobileElement e2 = driver.findElementByAccessibilityId("show alert"); TouchAction tap1 = new TouchAction(driver).tap(tapOptions().withElement(element(e))); TouchAction tap2 = new TouchAction(driver).tap(tapOptions().withElement(element(e2))); new MultiTouchAction(driver).add(tap1).add(tap2).perform(); WebDriverWait waiting = new WebDriverWait(driver, 10000); assertNotNull(waiting.until(alertIsPresent())); driver.switchTo().alert().accept(); }
/** * Accepting alert popups in browser. * @return whether an alert was accepted */ public static boolean acceptAlert() { if (isAlertShowing()) { getDriver().switchTo().alert().accept(); return true; } return false; }
public void acceptAlertDialog(Consumer<SebContext> showDialog) { boolean supportsAlerts = isAlertSupported(); if (!supportsAlerts) { ((JavascriptExecutor) context.getDriver()).executeScript("window.alert = function(msg){};"); } showDialog.accept(context); if (supportsAlerts) { context.getDriver().switchTo().alert().accept(); } }
@Override public Boolean apply(WebDriver webDriver) { if (isAlertPresent(webDriver)) { webDriver.switchTo().alert().accept(); return true; } else { return false; } } });
public void discardDraftForContent(String pageTitle) { PageElement discardLink = getDiscardLink(pageTitle); waitUntilTrue(discardLink.timed().isVisible()); discardLink.click(); // Accept confirmation dialog WebDriverWait wait = new WebDriverWait(driver, 2); // seconds wait.until(ExpectedConditions.alertIsPresent()); driver.switchTo().alert().accept(); }