List of usage examples for org.openqa.selenium Alert dismiss
void dismiss();
From source file:Testregdb1.java
private String closeAlertAndGetItsText() { try {//from ww w.j a v a2 s. co m Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
From source file:app.Stepdefs.java
private void popup(Boolean accept) { long timeout = 5000; long waitForAlert = System.currentTimeMillis() + timeout; boolean boolFound = false; do {// www . ja v a 2 s .c om try { Alert alert = this.driver.switchTo().alert(); if (alert != null) { if (accept) { alert.accept(); } // OK is accepted from the popup else { alert.dismiss(); } // Cancel is accepted from the popup boolFound = true; } } catch (NoAlertPresentException ex) { } } while ((System.currentTimeMillis() < waitForAlert) && (!boolFound)); }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java
License:Apache License
/** * {@inheritDoc}/* w w w .j ava2s . c om*/ */ @Override public Interact handleAlert(boolean accept) { try { new WebDriverWait(((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver(), DriverConfig.DEFAULT_IMPL_WAIT).until(ExpectedConditions.alertIsPresent()); Alert alert = ((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver().switchTo() .alert(); if (accept) alert.accept(); else alert.dismiss(); } catch (NoAlertPresentException e) { } return this; }
From source file:com.automationpractice.tests.AddTochart.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://automationpractice.com"); driver.findElement(By.xpath(".//*[@id='homefeatured']/li[1]/div/div[2]/div[2]/a[1]/span")).click(); driver.findElement(By.xpath(".//*[@id='layer_cart']/div[1]/div[2]/div[4]/a/span")).click(); if (driver.switchTo().alert() != null) { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); alert.dismiss(); // alert.accept(); }//from w ww . j a v a 2s. c om }
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
License:Open Source License
@Override public void dismissAlert() { try {/*from w w w . j av a 2 s .com*/ Alert a = webDriver.switchTo().alert(); String text = a.getText(); a.dismiss(); log.info("Dismissing alert: " + text); } catch (Exception e) { log.info(("We are hiding an exception here: " + e.getMessage())); } }
From source file:com.company.TestWithJavaScript.java
License:Apache License
@Test public void shouldShowAlertMessage() { try {//from w w w. j a v a 2 s. co m // given String message = "Hello world"; // when String code = format("alert('%s');", message); browser.executeJavascript(code); // then Alert alert = browser.switchTo().alert(); assertThat(alert.getText(), equalTo(message)); alert.dismiss(); } catch (JavascriptNotSupported ex) { throw new SkipTest("JavaScript not supported"); } }
From source file:com.consol.citrus.selenium.actions.AlertAction.java
License:Apache License
@Override protected void execute(SeleniumBrowser browser, TestContext context) { Alert alert = browser.getWebDriver().switchTo().alert(); if (alert == null) { throw new CitrusRuntimeException("Failed to access alert dialog - not found"); }//from w w w .j a va2s . com if (StringUtils.hasText(text)) { log.info("Validating alert text"); String alertText = context.replaceDynamicContentInString(text); if (ValidationMatcherUtils.isValidationMatcherExpression(alertText)) { ValidationMatcherUtils.resolveValidationMatcher("alertText", alert.getText(), alertText, context); } else { Assert.isTrue(alertText.equals(alert.getText()), String.format("Failed to validate alert dialog text, " + "expected '%s', but was '%s'", alertText, alert.getText())); } log.info("Alert text validation successful - All values Ok"); } context.setVariable(SeleniumHeaders.SELENIUM_ALERT_TEXT, alert.getText()); if (accept) { alert.accept(); } else { alert.dismiss(); } }
From source file:com.consol.citrus.selenium.client.WebClient.java
License:Apache License
public String cancelAlertBox() { String message = null;//from www . j av a2 s .co m try { Alert alert = webDriver.switchTo().alert(); message = alert.getText(); alert.dismiss(); } catch (Exception e) { message = null; } return message; }
From source file:com.dhenton9000.selenium.generic.UtilMethods.java
/** * handle an alert if no alert present error caught and reported * @param driver// w w w .j a v a2 s . c o m * @param doAccept */ public static void handleAlert(WebDriver driver, boolean doAccept) { try { Alert a = driver.switchTo().alert(); if (doAccept) a.accept(); else a.dismiss(); } catch (Exception err) { LOG.warn("handle alert error " + err.getClass().getName() + " " + err.getMessage()); } }
From source file:com.elastica.webelements.BasePage.java
License:Apache License
public String cancelConfirmation() throws NotCurrentPageException { Alert alert = driver.switchTo().alert(); String seenText = alert.getText(); alert.dismiss(); driver.switchTo().defaultContent();/* w w w . j ava 2s. c o m*/ return seenText; }