@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();
  }
  public static void main(String[] args) throws InterruptedException {
    System.setProperty(
        "webdriver.chrome.driver",
        "C:\\Users\\jakther\\Desktop\\jahed\\java\\chromedriver\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://test.salesforce.com");
    Thread.sleep(2000);

    driver.findElement(By.id("username")).sendKeys("*****@*****.**");
    driver.findElement(By.id("password")).sendKeys("06082003Tuba");
    driver.findElement(By.id("Login")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("Account_Tab")).click();
    Thread.sleep(2000);
    List<WebElement> list = driver.findElements(By.cssSelector(".dataCell>a"));
    System.out.println(list.size());
    for (int i = 0; i < list.size(); i++) {
      WebElement ele =
          driver.findElement(
              By.xpath(
                  ".//*[@id='bodyCell']/div[3]/div[1]/div/div[2]/table/tbody/tr["
                      + (i + 2)
                      + "]/th/a"));
      System.out.println(ele.getText());

      switch (ele.getText()) {
        case "MD J Akther":
          ele.click();
          Thread.sleep(2000);
          driver.findElement(By.xpath(".//*[@id='topButtonRow']/input[4]")).click();
          Thread.sleep(2000);

          try {
            Alert alert = driver.switchTo().alert();
            alert.accept();
            Thread.sleep(2000);
          } catch (Exception e) {
          }
          break;

        case "Akther Nabil":
          ele.click();
          Thread.sleep(2000);
          driver.findElement(By.xpath(".//*[@id='topButtonRow']/input[4]")).click();
          Thread.sleep(2000);

          try {
            Alert alert = driver.switchTo().alert();
            alert.accept();
            Thread.sleep(2000);
          } catch (Exception e) {
          }
          break;
        default:
      }
    }
  }
Exemplo n.º 3
0
  // Accept a confirmation
  public void waitForConfirmation(String confirmationText, int... wait) {
    String message = getTextFromAlert();
    int timeOut = wait.length > 0 ? wait[0] : DEFAULT_TIMEOUT;

    // log("confirmation: " + message);
    if (message.isEmpty()) {
      if (loopCount > timeOut / 500) {
        Assert.fail("Message is empty");
      }
      Utils.pause(500);
      loopCount++;
      waitForConfirmation(confirmationText);
      return;
    }

    for (int second = 0; ; second++) {
      if (second >= timeOut) {
        Assert.fail("Timeout at waitForConfirmation: " + confirmationText);
      }
      if (message.contains(confirmationText)) {
        break;
      }

      Utils.pause(100);
    }
    Alert alert = driver.switchTo().alert();
    alert.accept();
    Utils.pause(3000);
  }
Exemplo n.º 4
0
 protected void checkAlert() {
   try {
     Alert alert = driver.switchTo().alert();
     alert.accept();
   } catch (Exception e) {
   }
 }
Exemplo n.º 5
0
  protected File savePageSourceToFile(String fileName, WebDriver webdriver, boolean retryIfAlert) {
    File pageSource = new File(reportsFolder, fileName + ".html");

    try {
      writeToFile(webdriver.getPageSource(), pageSource);
    } catch (UnhandledAlertException e) {
      if (retryIfAlert) {
        try {
          Alert alert = webdriver.switchTo().alert();
          log.severe(e + ": " + alert.getText());
          alert.accept();
          savePageSourceToFile(fileName, webdriver, false);
        } catch (Exception unableToCloseAlert) {
          log.severe("Failed to close alert: " + unableToCloseAlert);
        }
      } else {
        printOnce("savePageSourceToFile", e);
      }
    } catch (UnreachableBrowserException e) {
      writeToFile(e.toString(), pageSource);
      return pageSource;
    } catch (Exception e) {
      writeToFile(e.toString(), pageSource);
      printOnce("savePageSourceToFile", e);
    }
    return pageSource;
  }
  protected void acceptConfirmation() {
    WebDriver.TargetLocator targetLocator = switchTo();

    Alert alert = targetLocator.alert();

    alert.accept();
  }
Exemplo n.º 7
0
  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();

    File file = new File("src/form.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);

    dr.get(filePath);
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=checkbox]")).click();
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=radio]")).click();
    Thread.sleep(1000);

    List<WebElement> options =
        dr.findElement(By.tagName("select")).findElements(By.tagName("option"));
    options.get(options.size() - 1).click();
    Thread.sleep(1000);

    dr.findElement(By.cssSelector("input[type=submit]")).click();

    Alert alert = dr.switchTo().alert();
    System.out.println(alert.getText());
    alert.accept();

    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit();
  }
  @Test
  public void basicPromptConfirmHandlingAcceptTest() {

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

    assertEquals("change me", promptResult.getText());
  }
Exemplo n.º 9
0
 public TrashSubPage emptyTrash() {
   findElementWaitUntilEnabledAndClick(By.id(EMPTY_TRASH_BUTTON_ID));
   Alert alert = driver.switchTo().alert();
   assertEquals("Permanently delete all documents in trash?", alert.getText());
   alert.accept();
   return asPage(TrashSubPage.class);
 }
Exemplo n.º 10
0
  public void AlertHandler() {
    try {
      Alert alert = driver.switchTo().alert();
      alert.accept();
    } catch (Exception e) {

    }
  }
Exemplo n.º 11
0
 public void clickPopUp() {
   try {
     Alert alert = driver.switchTo().alert();
     // System.out.println("Read from popup: " + alert.getText());
     alert.accept();
   } catch (Exception e) {
     System.out.println("Alert not present");
   }
 }
Exemplo n.º 12
0
 // Accept an alert
 public void acceptAlert() {
   try {
     Alert alert = driver.switchTo().alert();
     alert.accept();
     switchToParentWindow();
   } catch (NoAlertPresentException e) {
   }
   Utils.pause(1000);
 }
Exemplo n.º 13
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);
 }
  @Before
  public void setUp() {
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();

    driver.get("https://alpha-external.pay.naver.com/npoint/pay/charge.nhn?CHNL=NV#");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    // 일반 로그인
    driver.findElement(By.id("id")).sendKeys("nvqa_bill111");
    driver.findElement(By.id("pw")).sendKeys("btest789");
    driver.findElement(By.cssSelector("input.int_jogin")).click();

    // 사파리 진입 시, 알럿확인
    try {
      Alert alert = driver.switchTo().alert();
      // String textOnAlert = alert.getText();
      alert.accept();

      // assertEquals("계좌이체 및 신용카드포인트 결제는 IE에서 가능합니다.", textOnAlert);
    } catch (NoAlertPresentException e) {
      e.printStackTrace();
    }

    // 확인해주세요 팝업 확인

    /*	String parentWindowId = driver.getWindowHandle();

    		Set<String> allWindows = driver.getWindowHandles();
    		if (!allWindows.isEmpty()) {
    			for (String windowID : allWindows) {
    				driver.switchTo().window(windowID);
    				if (driver.getPageSource().contains("확인해 주세요.")) {
    					try {
    						WebElement noMoreButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/span"));
    						noMoreButton.click();

    						WebElement identifyButton = driver
    								.findElement(By
    										.xpath("//*[@id='infoPopupNGCASH']/div/p/a/img"));
    						identifyButton.click();
    						break;
    					} catch (NoSuchWindowException e) {
    						e.printStackTrace();
    					}
    				}
    			}
    		}

    		driver.switchTo().window(parentWindowId);
    */
  }
Exemplo n.º 15
0
 private void More메뉴_Webtoon을_클릭한다() {
   More메뉴에_마우스를_가져다놓는다();
   moveAndClick(By.xpath("//*[@id=\"navi\"]/div/ul/li[6]/div/ul/li[2]/a"));
   new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
   // alert을 닫는다.
   try {
     Thread.sleep(5 * 1000);
   } catch (InterruptedException e) {
   }
   Alert alert = driver.switchTo().alert();
   alert.accept();
 }
 /** @param model Verify the alert text */
 public void verifyalertText(MethodParameters model) {
   model.getElement().get(0).click();
   wait1(1000);
   Alert alert = WebDriverClass.getInstance().switchTo().alert();
   wait1(1000);
   if (!(alertText == null)) {
     alertText = null;
   }
   alertText = alert.getText();
   Assert.assertEquals(alertText.toString(), model.getData());
   alert.accept();
 }
Exemplo n.º 17
0
 private String closeAlertAndGetItsText() {
   try {
     Alert alert = driver.switchTo().alert();
     String alertText = alert.getText();
     if (acceptNextAlert) {
       alert.accept();
     } else {
       alert.dismiss();
     }
     return alertText;
   } finally {
     acceptNextAlert = true;
   }
 }
 protected String closeAlert(boolean confirm) {
   Alert alert = null;
   try {
     alert = webDriverCache.getCurrent().switchTo().alert();
     String text = alert.getText().replace("\n", "");
     if (!confirm) {
       alert.dismiss();
     } else {
       alert.accept();
     }
     return text;
   } catch (WebDriverException wde) {
     throw new Selenium2LibraryNonFatalException("There were no alerts");
   }
 }
  /** Alert accept meaning click on OK button */
  public void alertAccept(MethodParameters model) {

    WebDriverWait wait = new WebDriverWait(WebDriverClass.getDriver(), 30);
    wait.until(ExpectedConditions.alertIsPresent());

    MainTestNG.LOGGER.info("inside alertAccept()");

    wait1(2000);

    Alert alert = WebDriverClass.getInstance().switchTo().alert();
    wait1(2000);

    alert.accept();
    MainTestNG.LOGGER.info("completed alertAccept()");
  }
Exemplo n.º 20
0
 public static void itemEntry(WebDriver d) {
   WebElement slot = null;
   try {
     slot = d.findElement(By.xpath("//div[@class='slots']"));
   } catch (NoSuchElementException e) {
     return;
   }
   slot.click();
   try {
     d.findElement(By.xpath("//button[@id='getslots']")).click();
   } catch (NoSuchElementException e) {
     return;
   }
   try {
     Alert alert = d.switchTo().alert();
     if (!alert.getText().equals("Success!")) {
       alert.accept();
       itemEntry(d);
     }
     alert.accept();
   } catch (NoAlertPresentException e) {
     return;
   }
 }
Exemplo n.º 21
0
 /**
  * Close an Alert Pop Up
  *
  * @return
  */
 public boolean closeAlert() {
   // Get a handle to the open alert, prompt or confirmation
   try {
     Alert alert = se.driver().switchTo().alert();
     // And acknowledge the alert (equivalent to clicking "OK")
     alert.accept();
     se.log().logSeStep("Closing Alert");
     return true;
   } catch (Exception e) {
     // no alert
     se.log().logSeStep("Cannot Close Alert");
     e.printStackTrace();
     return false;
   }
 }
  public static String getConfirmation(WebDriver webDriver) {
    webDriver.switchTo();

    WebDriverWait webDriverWait = new WebDriverWait(webDriver, 1);

    try {
      Alert alert = webDriverWait.until(ExpectedConditions.alertIsPresent());

      String confirmation = alert.getText();

      alert.accept();

      return confirmation;
    } catch (Exception e) {
      throw new WebDriverException();
    }
  }
Exemplo n.º 23
0
 /**
  * @param driver
  * @param parentHandle
  *     <pre>{@code
  * This Method logs-off if enabled logoff param as true from
  * specified URL on AccessConfig Model loaded from Excel Sheet
  *
  * }</pre>
  */
 protected void logOffAndClose(WebDriver driver, String parentHandle) {
   try {
     if (getFrameElement(driver, "Menu") != null) {
       driver.switchTo().frame(getFrameElement(driver, "Menu"));
       WebElement logOffBtn = driver.findElement(By.linkText("Log Off"));
       logOffBtn.click();
       Alert alert = driver.switchTo().alert();
       alert.accept();
       driver.switchTo().window(parentHandle);
       WebElement signOutBtn = driver.findElement(By.linkText("Sign Out"));
       signOutBtn.click();
     }
     driver.quit();
   } catch (Exception e) {
     driver.quit();
     e.printStackTrace();
   }
 }
Exemplo n.º 24
0
 public static void main(String[] args) throws InterruptedException {
   ProjectSpecific.Login();
   driver.findElement(By.linkText("Leads")).click();
   Thread.sleep(2000);
   driver.findElement(By.xpath("//tr[td[a[text()='ZZ']]]//input[@type='checkbox']")).click();
   String v = driver.findElement(By.xpath("//tr[td[a[text()='ZZ']]]//td[3]")).getText();
   driver.findElement(By.xpath("//input[@value='Delete']")).click();
   Alert alt = driver.switchTo().alert();
   alt.accept();
   Thread.sleep(3000);
   ProjectSpecific.SearchItem(v, "Last Name");
   Thread.sleep(30000);
   String cmp = "No Lead Found !";
   String str = driver.findElement(By.xpath("//span[contains(text(),'No Lead Found')]")).getText();
   System.out.println(str);
   if (str.equals(cmp)) {
     System.out.println("deleted successfuly");
   }
 }
  public static void addFittingRoomTest(WebDriver driver) {
    System.out.println("\nStart adding items to Fitting Room tests");
    openWebsite(driver);
    sleep();

    for (int i = 0; i < category.length; i++) {
      WebElement element =
          driver
              .findElement(By.className((String) ("service-count" + (i + 1))))
              .findElement(By.id("img"));
      element.click();
      sleep();
      assertTrue(driver.getCurrentUrl(), location + category[i]);

      WebElement element2 = driver.findElement(By.id((String) ("item-img0")));
      element2.click();
      sleep();
      assertTrue(driver.getCurrentUrl(), location + category[i] + productsLists[i][0]);

      WebElement element3 =
          driver
              .findElement(By.id("mainview"))
              .findElement(By.id("description"))
              .findElement(By.id("add_to_fitlist"));
      element3.click();
      sleep();
      sleep();

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

      driver.navigate().back();
      openWebsite(driver);
      sleep();
    }

    WebElement element4 =
        driver.findElement(By.className("global-nav")).findElement(By.id("wishlist"));
    element4.click();
    sleep();
  }
Exemplo n.º 26
0
  @Test
  public void handlingSimpleAlertTest() {
    final String expected_alert_text =
        "A Short Title Is Best A message should be a short, complete sentence.";

    driver.findElement(MobileBy.AccessibilityId("alert_views_button")).click();
    // wait for alert view to load by waiting for "simple" alert button
    wait.until(
            ExpectedConditions.visibilityOf(
                driver.findElement(MobileBy.AccessibilityId("simple_alert_button"))))
        // and click on it
        .click();
    wait.until(ExpectedConditions.alertIsPresent());

    Alert alert = driver.switchTo().alert();
    String titleAndMessage = alert.getText();

    assertThat(titleAndMessage, is(expected_alert_text));
    alert.accept();
  }
  @Test
  public void basicConfirmHandlingAcceptTest() {

    WebElement confirmButton;
    WebElement confirmResult;

    confirmButton = driver.findElement(By.id("confirmexample"));
    confirmResult = driver.findElement(By.id("confirmreturn"));

    assertEquals("cret", confirmResult.getText());
    confirmButton.click();

    String alertMessage = "I am a confirm alert";

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

    assertEquals(alertMessage, confirmAlert.getText());

    confirmAlert.accept();

    assertEquals("true", confirmResult.getText());
  }
 public static void DieModalDie() {
   Alert alert = driver.switchTo().alert();
   alert.accept();
 }
Exemplo n.º 29
0
 public void clickLogout(WebDriver driver) {
   driver.findElement(logout).click();
   Alert alert = driver.switchTo().alert();
   System.out.println("Alert Present on page: " + alert.getText());
   alert.accept();
 }
 @Override
 public void acceptAlert() {
   Alert alert = waits.waitForAlertAndSwitch();
   alert.accept();
 }