org.openqa.selenium.Alert类的使用及代码示例

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

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

Alert介绍

暂无

代码示例

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

System.out.println(javascriptAlert.getText()); // Get text on alert box
javascriptAlert.accept();
javascriptprompt.sendKeys("This is Selenium Training");
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.dismiss();
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
javascriptconfirm.accept();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
javascriptconfirm.accept();
javascriptconfirm.dismiss();
javascriptconfirm = myTestDriver.switchTo().alert();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
javascriptconfirm.accept();

代码示例来源: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

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

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

// working with alerts.
   Alert alert = driver.switchTo().alert();
   // for clicking on ok button
   alert.accept();
   // for clicking on cancel button
   alert.dismiss();
   // for getting alert text message
   alert.getText();
   // for sending some text inside the alert
   alert.sendKeys("alert string");

代码示例来源:origin: com.github.ebour.selenium/selenium-factories-api

private void confirmAlertQuietly()
{
  try
  {
    webDriver.switchTo().alert().accept();
  }
  catch (Exception e)
  {
    // Ignore
  }
}

代码示例来源:origin: org.finra.jtaf/jtaf-extwebdriver

@Override
public String getNativeDialogText() {
  Alert alert = wd.switchTo().alert();
  return alert.getText();
}

代码示例来源: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: jenkinsci/acceptance-test-harness

@Override
public void confirmAlert(int timeout) {
  WebDriverWait wait = new WebDriverWait(driver, timeout);
  Alert promptAlert = wait.until(ExpectedConditions.alertIsPresent());
  promptAlert.accept();
}

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

WebDriver driver = new FirefoxDriver();  
  driver.get("https:www.google.com");
  WebDriverWait wait = new WebDriverWait(driver, 5 );

  try{

  if(wait.until(ExpectedConditions.alertIsPresent())==null)
  {
  System.out.println("alert was not present");
  }else{
    Alert alert = driver.switchTo().alert(); 
    alert.accept();
    System.out.println("alert was present");
    }

  }catch(Exception e){
    System.out.println("ignored alret not present exception" +e.getMessage());
  }

}

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

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

代码示例来源:origin: jenkinsci/acceptance-test-harness

/**
 * Adds a new user/group to this matrix.
 */
public MatrixRow addUser(String name) {
  this.name.resolve().findElement(by.parent()).findElement(by.button("Add user or group…")).click();
  WebDriverWait wait = new WebDriverWait(driver, 10);
  Alert promptAlert = wait.until(ExpectedConditions.alertIsPresent());
  promptAlert.sendKeys(name);
  promptAlert.accept();
  return getUser(name);
}

代码示例来源:origin: getgauge-examples/java-gradle-selenium

public void delete(WebDriver driver) {
    deleteButton.click();
    WebDriverWait wait = new WebDriverWait(driver, 2);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
  }
}

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

String alertText = "";
WebDriverWait wait = new WebDriverWait(driver, 5);
// This will wait for a maximum of 5 seconds, everytime wait is used

driver.findElement(By.xpath("//button[text() = \"Edit\"]")).click();//causes page to alert() something

wait.until(ExpectedConditions.alertIsPresent());
// Before you try to switch to the so given alert, he needs to be present.

Alert alert = driver.switchTo().alert();
alertText = alert.getText();
alert.accept();

return alertText;

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

private void removeExistingEvil()
{
  try
  {
    webDriver.switchTo().alert().dismiss();
  }
  catch (NoAlertPresentException iDontReallyCare)
  {
  }
}

代码示例来源:origin: com.infotel.seleniumRobot/core

public String cancelConfirmation() {
  Alert alert = getAlert();
  String seenText = alert.getText();
  alert.dismiss();
  driver.switchTo().defaultContent();
  return seenText;
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

private void cleanUp()
  {
    final WebDriver driver = webDriver.get();
    if (driver != null)
    {
      boolean hasAlert = ExpectedConditions.alertIsPresent().apply(driver) != null;
      if (hasAlert) {
        driver.switchTo().alert().dismiss();
      }
      driver.manage().deleteAllCookies();
    }
  }
}

代码示例来源:origin: testIT-WebTester/webtester-core

@Override
public void execute(Browser browser) {
  if (isAlertVisible()) {
    Alert alert = getWebDriver().switchTo().alert();
    String text = alert.getText();
    alert.accept();
    fireEvent(new AcceptedAlertEvent(browser, text));
  }
}

代码示例来源:origin: qaprosoft/carina

/**
 * Accepts alert modal.
 */
public void acceptAlert() {
  WebDriver drv = getDriver();
  Wait<WebDriver> wait = new WebDriverWait(drv, EXPLICIT_TIMEOUT, RETRY_TIME);
  try {
    wait.until((Function<WebDriver, Object>) dr -> isAlertPresent());
    drv.switchTo().alert().accept();
    Messager.ALERT_ACCEPTED.info("");
  } catch (Exception e) {
    Messager.ALERT_NOT_ACCEPTED.error("");
  }
}

代码示例来源:origin: qaprosoft/carina

/**
 * Cancels alert modal.
 */
public void cancelAlert() {
  WebDriver drv = getDriver();
  Wait<WebDriver> wait = new WebDriverWait(drv, EXPLICIT_TIMEOUT, RETRY_TIME);
  try {
    wait.until((Function<WebDriver, Object>) dr -> isAlertPresent());
    drv.switchTo().alert().dismiss();
    Messager.ALERT_CANCELED.info("");
  } catch (Exception e) {
    Messager.ALERT_NOT_CANCELED.error("");
  }
}

代码示例来源:origin: cloudgrey-io/appiumpro

public void actualTest(AppiumDriver driver) throws URISyntaxException, IOException {
    WebDriverWait wait = new WebDriverWait(driver, 10);

    try {
      // get to the photo view
      wait.until(ExpectedConditions.presenceOfElementLocated(photos)).click();

      // wait for and click the correct image using a reference image template
      By sunriseImage = MobileBy.image(getReferenceImageB64());
      wait.until(ExpectedConditions.presenceOfElementLocated(sunriseImage)).click();

      // verify that the resulting alert proves we clicked the right image
      wait.until(ExpectedConditions.alertIsPresent());
      String alertText = driver.switchTo().alert().getText();
      Assert.assertThat(alertText, Matchers.containsString("sunrise"));
    } finally {
      driver.quit();
    }
  }
}

相关文章