@Test
  public void basicPromptConfirmHandlingChangeAndDismissTest() {

    WebElement promptButton;
    WebElement promptResult;

    promptButton = driver.findElement(By.id("promptexample"));
    promptResult = driver.findElement(By.id("promptreturn"));

    assertEquals("pret", promptResult.getText());
    promptButton.click();

    String alertMessage = "I prompt you";

    Alert promptAlert = driver.switchTo().alert();

    if (Driver.currentDriver != Driver.BrowserName.IE) {
      // no point doing this in IE as we know it isn't the actual prompt
      assertEquals(alertMessage, promptAlert.getText());
    }

    promptAlert.sendKeys("Hello");
    promptAlert.dismiss();

    assertEquals("pret", promptResult.getText());
  }
  @Test
  public void test() throws InterruptedException {
    // Alert popup Handling.
    driver.findElement(By.xpath("input[@value='Show Me Alert']")).click();
    // To locate alert
    Alert A1 = driver.switchTo().alert();
    // To read the text from alert popup.
    String Alert1 = A1.getText();
    System.out.println(Alert1);
    Thread.sleep(2000);
    // To accept/Click OK on the alert popup
    A1.accept();

    // Confirmation Pop up handling.
    driver.findElement(By.xpath("//button[@onlick='myFunction()']")).click();
    Alert A2 = driver.switchTo().alert();
    String Alert2 = A2.getText();
    System.out.println(Alert2);
    Thread.sleep(2000);
    // To Click on cancel button of confirmation box.
    A2.dismiss();

    // Prompt pop up handling.
    driver.findElement(By.xpath("//button[contains(.,'Show Me Prompt')]")).click();
    Alert A3 = driver.switchTo().alert();
    String Alert3 = A3.getText();
    System.out.println(Alert3);
    // To type text Im text box of prompt pop up.
    A3.sendKeys("This is John");
    Thread.sleep(2000);
    A3.accept();
  }
예제 #3
0
 // Input text
 public void inputAlertText(String text) {
   try {
     Alert alert = driver.switchTo().alert();
     alert.sendKeys(text);
     alert.accept();
     switchToParentWindow();
   } catch (NoAlertPresentException e) {
   }
   Utils.pause(1000);
 }
예제 #4
0
  @Test
  public void textInputAlertTest() {
    driver.findElement(MobileBy.AccessibilityId("alert_views_button")).click();
    driver.findElement(MobileBy.AccessibilityId("text_entry_alert_button")).click();
    wait.until(ExpectedConditions.alertIsPresent());

    Alert alert = driver.switchTo().alert();
    String titleAndMessage = alert.getText();
    assertThat(
        titleAndMessage,
        is("A Short Title Is Best A message should be a short, complete sentence."));

    // input text
    String text_alert_message = "testing alert text input field";

    alert.sendKeys(text_alert_message);
    String alertTextInputField_value =
        driver.findElement(MobileBy.xpath("//UIAAlert//UIATextField")).getText();
    assertThat(alertTextInputField_value, is(text_alert_message));
  }
  /** Provide Login name for window authentication */
  public static void windowAuthenticationLoginName(MethodParameters model) {

    Alert alert = WebDriverClass.getDriver().switchTo().alert();
    alert.sendKeys(model.getData());
  }