// odi.614 Able to generate reports for time range public void search() { String dmName = "US_AIRWAYS"; gotoreports(dmName); try { driver.findElement(By.id("PARAM_START_DATE")).clear(); Alert alert = driver.switchTo().alert(); alert.dismiss(); driver.findElement(By.id("PARAM_START_DATE")).sendKeys("8/11/2013"); driver.findElement(By.id("PARAM_END_DATE")).clear(); alert.dismiss(); driver.findElement(By.id("PARAM_END_DATE")).sendKeys("9/11/2013"); driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); new WebDriverWait(driver, 10) .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent")); WebElement page = new WebDriverWait(driver, 10) .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer"))); WebElement rangeStart = page.findElement(By.xpath("//*[contains(text(),'8/11/2013')]")); WebElement rangeEnd = page.findElement(By.xpath("//*[contains(text(),'9/11/2013')]")); if (rangeStart != null && rangeEnd != null) { System.out.println("Report for selected range is showed"); } ReportFile = new WriteXmlFile(); driver.switchTo().defaultContent(); ReportFile.addTestCase("ODI6.x-614:CSSR-Search", "ODI6.x-614:CSSR-Search => Pass"); } catch (Exception e) { System.out.print("trace: "); e.printStackTrace(); } // driver.quit(); ReportFile.WriteToFile(); }
// Method for selecting a date public void pickAvalidDate() { driver.findElement(By.id("PARAM_START_DATE")).clear(); Alert alert = driver.switchTo().alert(); alert.dismiss(); driver.findElement(By.id("PARAM_START_DATE")).sendKeys("08/01/2013"); driver.findElement(By.id("PARAM_END_DATE")).clear(); alert.dismiss(); driver.findElement(By.id("PARAM_END_DATE")).sendKeys("09/01/2013"); driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); }
@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(); }
@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 basicPromptConfirmHandlingDismissTest() { 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) { // In IE the alert always returns "Script Prompt:" and not the // actual prompt text, so this line is just to alert me if the // functionality changes if (!promptAlert.getText().equals("Script Prompt:")) { throw new RuntimeException("IE now does not do Script Prompt"); } } else { // only check the alert prompt if not in IE assertEquals(alertMessage, promptAlert.getText()); } promptAlert.dismiss(); assertEquals("pret", promptResult.getText()); }
// Cancel an Alert public void cancelAlert() { try { Alert alert = driver.switchTo().alert(); alert.dismiss(); switchToParentWindow(); } catch (NoAlertPresentException e) { } Utils.pause(1000); }
public static void VerifyPopUpForDelete() throws Exception { GenericClass.clickElement(FstCheckBox); GenericClass.clickElement(DeleteSeasonBtn); Alert al = GenericClass.driver.switchTo().alert(); al.getText(); al.dismiss(); System.out.print("Alert Message"); Reporter.log("Pop up showing when deleting Season", true); }
public static void main(String[] args) { WebDriver wd = new FirefoxDriver(); wd.get("http://www.tizag.com/javascriptT/javascriptalert.php"); wd.findElement( By.xpath("/html/body/table[3]/tbody/tr[1]/td[2]/table/tbody/tr/td/div[4]/form/input")) .click(); Alert a = wd.switchTo().alert(); a.dismiss(); }
/** Alert dismiss meaning click on Cancel button */ public void alertDismiss(MethodParameters model) { WebDriverWait wait = new WebDriverWait(WebDriverClass.getDriver(), 30); wait.until(ExpectedConditions.alertIsPresent()); MainTestNG.LOGGER.info("inside alertDismiss()"); wait1(2000); model.getElement().get(0).click(); Alert alert = WebDriverClass.getInstance().switchTo().alert(); wait1(2000); alert.dismiss(); }
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"); } }
public static String alertConfirm() { String alertText = ""; try { Alert alert = driver.switchTo().alert(); alertText = alert.getText(); alert.dismiss(); // or accept as below // alert.accept(); } catch (NoAlertPresentException nape) { // nothing to do, because we only want to close it when pop up System.out.println("Alert not found!"); } return alertText; }
@Test public void basicConfirmHandlingDismissTest() { 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.dismiss(); assertEquals("false", confirmResult.getText()); }
public static void CancelDeletePopUp() throws Exception { String Season = GenericClass.getText(FirstSeason); GenericClass.clickElement(FstCheckBox); GenericClass.clickElement(DeleteSeasonBtn); Alert A1 = GenericClass.driver.switchTo().alert(); Reporter.log("Alert detected", true); String Alert1 = A1.getText(); System.out.println("Pop_UpText :" + Alert1); A1.dismiss(); int trcount = GenericClass.tr_count(CheckBox); int tr = trcount + 2; for (int i = 2; i <= tr; i++) { String getSeason = GenericClass.driver .findElement(By.xpath("//table[@id='mainSeasonTable']//tr[" + i + "]//td[3]")) .getText(); if (getSeason.equals(Season)) { System.out.println(Season + " Matched"); break; } } }
public void cancelAlert() { Alert alert = driver.switchTo().alert(); alert.dismiss(); }