org.openqa.selenium.Alert.accept()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中org.openqa.selenium.Alert.accept()方法的一些代码示例,展示了Alert.accept()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Alert.accept()方法的具体详情如下:
包路径:org.openqa.selenium.Alert
类名称:Alert
方法名:accept

Alert.accept介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

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
  }
}

代码示例来源:origin: stackoverflow.com

javascriptAlert.accept();
javascriptprompt.accept();
javascriptprompt = myTestDriver.switchTo().alert();
javascriptprompt.accept();
javascriptprompt.accept();
javascriptconfirm.accept();
javascriptconfirm.accept();
javascriptconfirm = myTestDriver.switchTo().alert();
javascriptconfirm.accept();

代码示例来源:origin: selenide/selenide

public String confirm(String expectedDialogText) {
 Alert alert = driver.switchTo().alert();
 String actualDialogText = alert.getText();
 alert.accept();
 checkDialogText(driver, expectedDialogText, actualDialogText);
 return actualDialogText;
}

代码示例来源:origin: selenide/selenide

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;
}

代码示例来源:origin: selenide/selenide

Alert alert = webdriver.switchTo().alert();
log.severe(e + ": " + alert.getText());
alert.accept();
savePageSourceToFile(config, fileName, webdriver, false);

代码示例来源:origin: appium/java-client

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();
  }
}

代码示例来源:origin: stackoverflow.com

new WebDriverWait(driver, 60)
    .ignoring(NoAlertPresentException.class)
    .until(ExpectedConditions.alertIsPresent());

Alert al = driver.switchTo().alert();
al.accept();

代码示例来源:origin: appium/java-client

@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();
  }
}

代码示例来源:origin: appium/java-client

@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());
}

代码示例来源:origin: stackoverflow.com

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();
  }
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: io.github.aktoluna/slnarch-core

public void accept() {
 dispatcher.beforeAlertAccept(driver);
 alert.accept();
 dispatcher.afterAlertAccept(driver);
}

代码示例来源:origin: com.daveayan/gherkinsalad.core

public void javascript_popup_click_ok() {
  Alert alert = get_current_alert_box();
  if(alert != null) {
    action("Accepted the javascript popup '" + alert.getText() + "'");
    alert.accept();
  }
}

代码示例来源:origin: com.atlassian.confluence/confluence-stateless-test-runner

/**
   * 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;
  }
}

代码示例来源:origin: com.atlassian.confluence/confluence-webdriver-pageobjects

public void clickDeleteAndConfirm() {
  this.deleteLink.click();
  Alert alert = driver.switchTo().alert();
  if (alert != null) {
    alert.accept();
  }
}

代码示例来源:origin: appium/java-client

@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();
}

代码示例来源:origin: io.wcm.qa/io.wcm.qa.galenium.galenium

/**
 * 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;
}

代码示例来源:origin: cz.etnetera/seb

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();
  }
}

代码示例来源:origin: Wikia/selenium-tests

@Override
 public Boolean apply(WebDriver webDriver) {
  if (isAlertPresent(webDriver)) {
   webDriver.switchTo().alert().accept();
   return true;
  } else {
   return false;
  }
 }
});

代码示例来源:origin: com.atlassian.confluence/confluence-webdriver-pageobjects

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();
}

相关文章