List of usage examples for org.openqa.selenium.support.ui ExpectedConditions alertIsPresent
public static ExpectedCondition<Alert> alertIsPresent()
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Close alert.// w w w.jav a 2 s . c o m * * @param driver the driver */ public static void closeAlert(WebDriver driver) { try { WebDriverWait wait = new WebDriverWait(driver, SHORT_TIMEOUT); if (wait.until(ExpectedConditions.alertIsPresent()) != null) { driver.switchTo().alert().accept(); } } catch (Exception e) { // ignore any exception } }
From source file:com.example.selenium.action.ExecuteJavaScript.java
@Test public void testJavaScriptCalls() throws Exception { JavascriptExecutor js = (JavascriptExecutor) driver; if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("sendgetreq()"); new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent()); // Get the Alert Alert alert = driver.switchTo().alert(); String response = alert.getText(); Thread.sleep(1000);// ww w .j av a 2 s . c om alert.accept(); Assert.assertEquals("HTTP Respose Success", response); } }
From source file:com.example.selenium.FormPage.java
public boolean validateFormPage(UserForm bean) { try {//from w ww.ja v a2s .c om textInput.sendKeys(bean.getText1()); Thread.sleep(1000); placeHolder.sendKeys(bean.getText2()); Thread.sleep(1000); //File Upload file.click(); Thread.sleep(2000); StringSelection ss = new StringSelection(bean.getFilePath()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null); //imitate mouse events like ENTER, CTRL+C, CTRL+V Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); Thread.sleep(2000); textArea.sendKeys(bean.getTextArea()); Thread.sleep(1000); if (bean.isCheckBox1()) { checkBox1.click(); } else if (bean.isCheckBox2()) { checkBox2.click(); } else if (bean.isCheckBox3()) { checkBox3.click(); } Thread.sleep(1000); inlineCheckBox.click(); if (bean.isRadio1()) { radioButton1.click(); } else if (bean.isRadio2()) { radioButton2.click(); } else if (bean.isRadio3()) { radioButton3.click(); } radioButton1.click(); Thread.sleep(1000); radioInline.click(); dropDown.click(); Select dropSelect = new Select(dropDown); dropSelect.selectByIndex(Integer.parseInt(bean.getDropDownSelect())); Thread.sleep(1000); multidropDown.click(); Select multidropSelect = new Select(multidropDown); for (String str : bean.getDropMultiSelect()) { multidropSelect.selectByIndex(Integer.parseInt(str)); } Thread.sleep(1000); submit.click(); new WebDriverWait(selenium, 10).until(ExpectedConditions.alertIsPresent()); // Get the Alert Alert alert = selenium.switchTo().alert(); alert.accept(); } catch (Exception ex) { Logger.getLogger(FormPage.class.getName()).log(Level.SEVERE, null, ex); } return true; }
From source file:com.ggasoftware.uitest.utils.Alerts.java
License:Open Source License
/** * Get alert.//from w w w .ja v a 2s. c om * * @param timeoutSec to wait until alert is exists. * @return Alert */ public static Alert getAlert(int timeoutSec) { WebDriverWait wait = new WebDriverWait(WebDriverWrapper.getDriver(), timeoutSec); wait.until(ExpectedConditions.alertIsPresent()); return WebDriverWrapper.getDriver().switchTo().alert(); }
From source file:com.ggasoftware.uitest.utils.Alerts.java
License:Open Source License
/** * Find alert from web page.//ww w .j a v a 2 s .c o m * * @param timeoutSec to wait until alert is exists. * @return true if alert is presents at web page, otherwise false */ public static boolean findAlert(int timeoutSec) { WebDriverWait wait = new WebDriverWait(WebDriverWrapper.getDriver(), timeoutSec); try { wait.until(ExpectedConditions.alertIsPresent()); return true; } catch (TimeoutException e) { return false; } }
From source file:com.hotwire.selenium.tools.c3.customer.itineraryDetails.C3HotelItineraryPage.java
License:Open Source License
public void createManualCredit(String amountDollars) { findOne(By.name("selectedCreditReason"), DEFAULT_WAIT).sendKeys("Other"); findOne(By.name("creditAmountString")).sendKeys(amountDollars); findOne(By.name("creditButton")).click(); new WebDriverWait(getWebDriver(), DEFAULT_WAIT).until(ExpectedConditions.alertIsPresent()).accept(); }
From source file:com.hotwire.selenium.tools.c3.customer.itineraryDetails.C3HotelItineraryPage.java
License:Open Source License
public void createManualBilling(String amountDollars) { findOne(By.name("selectedDebitReason"), DEFAULT_WAIT).sendKeys("Other"); findOne(By.name("debitAmountString")).sendKeys(amountDollars); findOne(By.name("debitButton")).click(); new WebDriverWait(getWebDriver(), DEFAULT_WAIT).until(ExpectedConditions.alertIsPresent()).accept(); }
From source file:com.hotwire.test.steps.application.AbstractApplication.java
License:Apache License
protected void acceptAlert() { WebDriverWait wait = new WebDriverWait(getAppiumDriver(), 2); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = getAppiumDriver().switchTo().alert(); alert.accept();// w w w.ja v a 2 s .com }
From source file:com.hotwire.test.steps.bex.BexAbstractModel.java
License:Open Source License
public void acceptAlert() { LOGGER.info("Wait for alert message in {} sec..", DEFAULT_WAIT); new WebDriverWait(getWebdriverInstance(), DEFAULT_WAIT).until(ExpectedConditions.alertIsPresent()).accept(); LOGGER.info("Alert is accepted.."); }
From source file:com.liferay.blade.samples.servicebuilder.web.BladeServiceBuilderWebTest.java
License:Apache License
protected static boolean isAlertPresent(WebDriver webDriver) { WebDriverWait webDriverWait = new WebDriverWait(webDriver, 3); try {/*from ww w.j ava2 s. com*/ ExpectedCondition<Alert> alert = ExpectedConditions.alertIsPresent(); webDriverWait.until(alert); return true; } catch (org.openqa.selenium.TimeoutException te) { return false; } }