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

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

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

Alert.getText介绍

暂无

代码示例

代码示例来源: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
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
System.out.println(javascriptprompt.getText()); // Get text on alert box
System.out.println(javascriptprompt.getText()); // Get text on alert box
javascriptprompt.accept();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
javascriptconfirm.accept();
System.out.println(javascriptconfirm.getText()); // Get text on alert box
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 dismiss(String expectedDialogText) {
 Alert alert = driver.switchTo().alert();
 String actualDialogText = alert.getText();
 alert.dismiss();
 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

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

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

@Test public void getAlertTextTest() {
    driver.findElement(MobileBy.AccessibilityId(iOSAutomationText)).click();
    waiting.until(alertIsPresent());
    assertFalse(StringUtils.isBlank(driver.switchTo().alert().getText()));
  }
}

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

// WARNING! Untested code written from memory without
// benefit of an IDE! May not be exactly correct!

// Switch the driver context to the alert
Alert alertDialog = driver.switchTo().alert();

// Get the alert text
String alertText = alertDialog.getText();

// Click the OK button on the alert.
alertDialog.accept();

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

Alert alert = driver.switchTo().alert();
 String alertText = alert.getText();
 if (alertText.equals("error...")) {
   // Do Something...
   // dismiss alert
   alert.dismiss();
 }

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

driver.get("http://www.httpwatch.com/httpgallery/authentication/#showExample10");
  // open URL
  driver.findElement(By.id("displayImage")).click();
  Thread.sleep(2000);
  driver.switchTo().alert();
  Alert promptAlert  = driver.switchTo().alert();
  String alertText = promptAlert .getText();
  System.out.println("Alert text is " + alertText);
  promptAlert.dismiss();

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

WebDriverWait wait = new WebDriverWait(5, TimeUnit.Seconds);

element.click();

// Wait for the dialog to show
wait.until(ExpectedConditions.alertIsPresent());

// Switch the driver context to the alert
Alert alertDialog = driver.switchTo().alert();

// Get the alert text
String alertText = alertDialog.getText();

// Click the OK button on the alert.
alertDialog.accept();

代码示例来源:origin: net.serenity-bdd/serenity-screenplay-webdriver

@Override
  public String answeredBy(Actor actor) {
    return BrowseTheWeb.as(actor).getAlert().getText();
  }
}

代码示例来源: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: org.jspringbot/jspringbot-selenium

private String closeAlert(boolean confirm) {
  Alert alert = driver.switchTo().alert();
  String text = alert.getText();
  if (!confirm) {
    alert.dismiss();
  } else {
    alert.accept();
  }
  return text;
}

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

public void javascript_popup_dismiss() {
  if(browser.is_Chrome()) {
    javascript_popup_click_ok();
    return;
  }
  Alert alert = get_current_alert_box();
  if(alert != null) {
    action("Dismissed the javascript popup '" + alert.getText() + "'");
    alert.dismiss();
  }
}

代码示例来源:origin: com.technophobia.substeps/webdriver-substeps

@Step("DismissAlert with message \"([^\"]*)\"")
  public void dismissAlertWithMessage(final String message) {

    // Get a handle to the open alert, prompt or confirmation

    final Alert alert = webDriverContext().getWebDriver().switchTo().alert();
    // this will throw a org.openqa.selenium.NoAlertPresentException if no
    // alert is present

    Assert.assertThat(alert.getText(), is(message));
    // And acknowledge the alert (equivalent to clicking "OK")
    alert.accept();
  }
}

代码示例来源:origin: org.jspringbot/jspringbot-selenium

public boolean isAlertPresent() {
  try {
    Alert alert = driver.switchTo().alert();
    LOG.keywordAppender().appendArgument("Message", alert.getText());
    return true;
  } catch (NoAlertPresentException ex) {
    LOG.info("Did not find any alerts.");
    return false;
  }
}

代码示例来源:origin: vmi/selenese-runner-java

@Override
  public String execute(Context context, String... args) {
    Alert alert = context.getWrappedDriver().switchTo().alert();
    String result = alert.getText();
    context.getNextNativeAlertActionListener().actionPerformed(alert);
    return result;
  }
}

相关文章