类org.openqa.selenium.NoAlertPresentException源码实例Demo

下面列出了怎么用org.openqa.selenium.NoAlertPresentException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: aquality-selenium-java   文件: Browser.java
/**
 * Accepts or declines prompt with sending message
 *
 * @param alertAction accept or decline
 * @param text        message to send
 */
public void handlePromptAlert(AlertActions alertAction, String text) {
    try {
        Alert alert = getDriver().switchTo().alert();
        if (text != null && !text.isEmpty()) {
            getDriver().switchTo().alert().sendKeys(text);
        }
        if (alertAction.equals(AlertActions.ACCEPT)) {
            alert.accept();
        } else {
            alert.dismiss();
        }
    } catch (NoAlertPresentException exception) {
        localizedLogger.fatal("loc.browser.alert.fail", exception);
        throw exception;
    }
}
 
源代码2 项目: bobcat   文件: ClosingAwareWebDriverWrapperTest.java
@Test
public void shouldTryToCloseAlertWhenNotMobileDuringCleanup() {
  //given
  setUp(IS_MAXIMIZED, IS_REUSABLE, NOT_MOBILE);
  when(webDriver.manage()).thenReturn(options);
  when(webDriver.manage().window()).thenReturn(window);
  when(webDriver.switchTo()).thenReturn(bobcatTargetLocator);
  when(webDriver.switchTo().alert()).thenReturn(alert);
  doThrow(new NoAlertPresentException()).when(alert).accept();

  //when
  testedObject.quit();

  //then
  verify(alert).accept();
}
 
源代码3 项目: PatatiumWebUi   文件: ElementAction.java
/**
 * 获取对话框文本
 * @return 返回String
 */
public String getAlertText()
{
	Alert alert=driver.switchTo().alert();
	try {
		String text=alert.getText().toString();
		log.info("获取对话框文本:"+text);
		return text;
	} catch (NoAlertPresentException notFindAlert) {
		// TODO: handle exception
		log.error("找不到对话框");
		//return "找不到对话框";
		throw notFindAlert;

	}
}
 
源代码4 项目: selenium   文件: ExpectedConditions.java
public static ExpectedCondition<Alert> alertIsPresent() {
  return new ExpectedCondition<Alert>() {
    @Override
    public Alert apply(WebDriver driver) {
      try {
        return driver.switchTo().alert();
      } catch (NoAlertPresentException e) {
        return null;
      }
    }

    @Override
    public String toString() {
      return "alert to be present";
    }
  };
}
 
源代码5 项目: product-es   文件: ESXSSTestCase.java
@Test(groups = "wso2.es.common", description = "Test XSS in Gadgets Page")
public void testListGadgetsXSSTestCase() throws Exception {

    String alertMessage = "XSS";

    String url = baseUrl + "/store/assets/gadget/list?" +
            "sortBy=overview_name&sort=}</script><script>alert('" + alertMessage + "')</script>";
    driver.get(url);

    boolean scriptInjected = false;

    try {
        String actualAlertMessage = closeAlertAndGetItsText(driver, false);

        if (actualAlertMessage.equals(alertMessage))
            scriptInjected = true;
    } catch (NoAlertPresentException ex) {
    }

    assertFalse(scriptInjected, "Script injected via the query string");
}
 
源代码6 项目: vividus   文件: WaitActionsTests.java
private void testWaitForPageLoadSleepForTimeout()
{
    Mockito.lenient().when(targetLocator.alert()).thenThrow(new NoAlertPresentException());
    mockDescriptiveWait(ChronoUnit.DAYS);
    when(javascriptActions.executeScript(SCRIPT_READY_STATE)).thenReturn(COMPLETE);
    spy.waitForPageLoad();
    verify(spy).sleepForTimeout(TIMEOUT_MILLIS);
}
 
源代码7 项目: vividus   文件: AlertActionsTests.java
@Test
void testIsAlertPresentNoAlertPresentException()
{
    when(webDriver.switchTo()).thenReturn(targetLocator);
    doThrow(NoAlertPresentException.class).when(targetLocator).alert();
    boolean answer = alertActions.isAlertPresent(webDriver);
    assertFalse(answer);
}
 
源代码8 项目: htmlunit   文件: WebDriverTestCase.java
/**
 * Gets the alerts collected by the driver.
 * Note: it currently works only if no new page has been loaded in the window
 * @param maxWaitTime the maximum time to wait to get the alerts (in millis)
 * @param driver the driver
 * @param alertsLength the expected length of Alerts
 * @return the collected alerts
 * @throws Exception in case of problem
 */
protected List<String> getCollectedAlerts(final long maxWaitTime, final WebDriver driver, final int alertsLength)
        throws Exception {
    final List<String> collectedAlerts = new ArrayList<>();

    long maxWait = System.currentTimeMillis() + maxWaitTime;

    while (collectedAlerts.size() < alertsLength && System.currentTimeMillis() < maxWait) {
        try {
            final Alert alert = driver.switchTo().alert();
            final String text = alert.getText();

            collectedAlerts.add(text);
            alert.accept();

            // handling of alerts requires some time
            // at least for tests with many alerts we have to take this into account
            maxWait += 100;

            if (useRealBrowser()) {
                if (getBrowserVersion().isIE()) {
                    // alerts for real IE are really slow
                    maxWait += 5000;
                }
            }
        }
        catch (final NoAlertPresentException e) {
            Thread.sleep(10);
        }
    }

    return collectedAlerts;
}
 
源代码9 项目: ats-framework   文件: AbstractRealBrowserDriver.java
/**
 *
* @return {@link Alert} object representing HTML alert, prompt or confirmation modal dialog
 */
private Alert getAlert() {

    try {
        return this.webDriver.switchTo().alert();
    } catch (NoAlertPresentException e) {
        throw new ElementNotFoundException(e);
    }
}
 
源代码10 项目: ats-framework   文件: RealHtmlElementState.java
/**
 *
 * @return {@link Alert} object representing HTML alert, prompt or confirmation modal dialog
 */
private Alert getAlert() {

    try {
        return this.webDriver.switchTo().alert();
    } catch (NoAlertPresentException e) {
        return null;
    }
}
 
private boolean isAlertPresent(WebDriver Driver) {
    try {
        Driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, e);
        return false;
    }
}
 
private boolean isAlertPresent(WebDriver Driver) {
    try {
        Driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.OFF, e.getMessage(), e);
        return false;
    }
}
 
public boolean isAlertPresent() {
    try {
        Driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, e);
        return false;
    }
}
 
源代码14 项目: nifi-registry   文件: ITCreateDuplicateBucket.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码15 项目: nifi-registry   文件: ITCreateMultipleBuckets.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码16 项目: nifi-registry   文件: ITRenameBucket.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码17 项目: nifi-registry   文件: ITDeleteSingleBucket.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码18 项目: nifi-registry   文件: ITCreateBucketCancel.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码19 项目: nifi-registry   文件: ITDeleteSingleBucketCancel.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码20 项目: nifi-registry   文件: ITCreateBucket.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码21 项目: nifi-registry   文件: ITRenameBucketDuplicate.java
private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
 
源代码22 项目: bobcat   文件: ClosingAwareWebDriverWrapper.java
private void cleanDriver() {
  manage().deleteAllCookies();
  get(BLANK_PAGE);
  if (!mobile) {
    try {
      switchTo().alert().accept();
    } catch (NoAlertPresentException e) {
      LOG.debug("No alert was present when returnDriver was executed", e);
    }
  }
  if (maximize) {
    manage().window().maximize();
  }
}
 
源代码23 项目: webtester2-core   文件: AlertHandler.java
/**
 * Accept any displayed alert message. If no alert is displayed, an exception will be thrown.
 * <p>
 * Fires {@link AcceptedAlertEvent} in case a alert was successfully accepted.
 *
 * @throws NoAlertPresentException in case no alert is present
 * @see Alert#accept()
 * @since 2.0
 */
public void accept() throws NoAlertPresentException {
    StringBuilder builder = new StringBuilder();
    ActionTemplate.browser(browser()).execute(browser -> {
        Alert alert = webDriver().switchTo().alert();
        builder.append(alert.getText());
        alert.accept();
    }).fireEvent(browser -> new AcceptedAlertEvent(builder.toString()));
    log.debug("alert was accepted");
}
 
源代码24 项目: webtester2-core   文件: AlertHandler.java
/**
 * Declines any displayed alert message. If no alert is displayed, an exception will be thrown.
 * <p>
 * Fires {@link DeclinedAlertEvent} in case a alert was successfully accepted.
 *
 * @throws NoAlertPresentException in case no alert is present
 * @see Alert#dismiss()
 * @since 2.0
 */
public void decline() throws NoAlertPresentException {
    StringBuilder builder = new StringBuilder();
    ActionTemplate.browser(browser()).execute(browser -> {
        Alert alert = webDriver().switchTo().alert();
        builder.append(alert.getText());
        alert.dismiss();
    }).fireEvent(browser -> new DeclinedAlertEvent(builder.toString()));
    log.debug("alert was declined");
}
 
源代码25 项目: PatatiumWebUi   文件: ElementAction.java
/**
 * 点击确认按钮
 */
public void alertConfirm()
{
	Alert alert=driver.switchTo().alert();
	try {
		alert.accept();
		log.info("点击确认按钮");
	} catch (NoAlertPresentException notFindAlert) {
		// TODO: handle exception
		//throw notFindAlert;
		log.error("找不到确认按钮");
		throw notFindAlert;
	}
}
 
源代码26 项目: PatatiumWebUi   文件: ElementAction.java
/**
 * 点击取消按钮
 */
public  void alertDismiss()
{
	Alert alert= driver.switchTo().alert();
	try {
		alert.dismiss();
		log.info("点击取消按钮");
	} catch (NoAlertPresentException notFindAlert) {
		// TODO: handle exception
		//throw notFindAlert;
		log.error("找不到取消按钮");
		throw notFindAlert;
	}
}
 
源代码27 项目: SeleniumCucumber   文件: AlertHelper.java
public boolean isAlertPresent() {
	try {
		driver.switchTo().alert();
		oLog.info("true");
		return true;
	} catch (NoAlertPresentException e) {
		// Ignore
		oLog.info("false");
		return false;
	}
}
 
源代码28 项目: product-cep   文件: DataSourcesTestCase.java
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - description field")
public void testXSSVenerabilityDescriptionField() throws Exception {
    boolean isVulnerable = false;

    // Login
    driver.get(getLoginURL());
    driver.findElement(By.id("txtUserName")).clear();
    driver.findElement(By.id("txtUserName")).sendKeys(cepServer.getContextTenant().getContextUser().getUserName());
    driver.findElement(By.id("txtPassword")).clear();
    driver.findElement(By.id("txtPassword")).sendKeys(cepServer.getContextTenant().getContextUser().getPassword());
    driver.findElement(By.cssSelector("input.button")).click();

    // Sending request to even-tracer admin service
    String url = backendURL.substring(0, 22) + "/carbon/ndatasource/newdatasource.jsp?";
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("description", "RiskScoringDB\"><script>alert(1)</script><example attr=\""));
    params.add(new BasicNameValuePair("edit", "true"));
    url += URLEncodedUtils.format(params, "UTF-8");

    driver.get(url);
    try {
        // Alert appears if vulnerable to XSS attack.
        Alert alert = driver.switchTo().alert();
        alert.accept();
        isVulnerable = true;
    } catch (NoAlertPresentException e) {
        // XSS vulnerability is not there
    }
    Assert.assertFalse(isVulnerable);
    driver.close();
}
 
源代码29 项目: product-cep   文件: DataSourcesTestCase.java
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - driver field")
public void testXSSVenerabilityDriverField() throws Exception {
    boolean isVulnerable = false;

    // Login
    driver.get(getLoginURL());
    driver.findElement(By.id("txtUserName")).clear();
    driver.findElement(By.id("txtUserName")).sendKeys(cepServer.getContextTenant().getContextUser().getUserName());
    driver.findElement(By.id("txtPassword")).clear();
    driver.findElement(By.id("txtPassword")).sendKeys(cepServer.getContextTenant().getContextUser().getPassword());
    driver.findElement(By.cssSelector("input.button")).click();

    // Sending request to even-tracer admin service
    String url = backendURL.substring(0, 22) + "/carbon/ndatasource/validateconnection-ajaxprocessor.jsp?";
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("dsName", "John"));
    params.add(new BasicNameValuePair("driver", "<script>alert(1)</script>"));
    params.add(new BasicNameValuePair("url", "http://abc.com"));
    params.add(new BasicNameValuePair("username", "John"));
    params.add(new BasicNameValuePair("dsType", "RDBMS"));
    params.add(new BasicNameValuePair("dsProviderType", "default"));
    url += URLEncodedUtils.format(params, "UTF-8");

    driver.get(url);
    try {
        // Alert appears if vulnerable to XSS attack.
        Alert alert = driver.switchTo().alert();
        alert.accept();
        isVulnerable = true;
    } catch (NoAlertPresentException e) {
        // XSS vulnerability is not there
    }
    Assert.assertFalse(isVulnerable);
    driver.close();
}
 
源代码30 项目: product-cep   文件: DataSourcesTestCase.java
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - data source name field")
public void testXSSVenerabilityNameField() throws Exception {
    boolean isVulnerable = false;

    // Login
    driver.get(getLoginURL());
    driver.findElement(By.id("txtUserName")).clear();
    driver.findElement(By.id("txtUserName")).sendKeys(cepServer.getContextTenant().getContextUser().getUserName());
    driver.findElement(By.id("txtPassword")).clear();
    driver.findElement(By.id("txtPassword")).sendKeys(cepServer.getContextTenant().getContextUser().getPassword());
    driver.findElement(By.cssSelector("input.button")).click();

    // Sending request to even-tracer admin service
    String url = backendURL.substring(0, 22) + "/carbon/ndatasource/newdatasource.jsp?";
    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("dsName", "RiskScoringDB\"><script>alert(1)</script><example attr=\""));
    params.add(new BasicNameValuePair("edit", "true"));
    url += URLEncodedUtils.format(params, "UTF-8");

    driver.get(url);
    try {
        // Alert appears if vulnerable to XSS attack.
        Alert alert = driver.switchTo().alert();
        alert.accept();
        isVulnerable = true;
    } catch (NoAlertPresentException e) {
        // XSS vulnerability is not there
    }
    Assert.assertFalse(isVulnerable);
    driver.close();
}
 
 类所在包
 同包方法