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

项目: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;

    }
}
项目:alex    文件:AlertAcceptDismissAction.java   
@Override
protected ExecuteResult execute(final WebSiteConnector connector) {
    try {
        final Alert alert = connector.getDriver().switchTo().alert();

        if (this.action == Action.ACCEPT) {
            alert.accept();

            LOGGER.info(LEARNER_MARKER, "Accept alert window (ignoreFailure: {}, negated: {}).",
                        ignoreFailure, negated);
        } else {
            alert.dismiss();

            LOGGER.info(LEARNER_MARKER, "Dismiss alert window (ignoreFailure: {}, negated: {}).",
                        ignoreFailure, negated);
        }

        return getSuccessOutput();
    } catch (NoAlertPresentException e) {
        LOGGER.info(LEARNER_MARKER, "Failed accept or dismiss alert window (ignoreFailure: {}, negated: {}).",
                    ignoreFailure, negated);

        return getFailedOutput();
    }
}
项目:alex    文件:AlertGetTextAction.java   
@Override
public ExecuteResult execute(final ConnectorManager connector) {
    final VariableStoreConnector variableStore = connector.getConnector(VariableStoreConnector.class);
    final WebSiteConnector webSiteConnector = connector.getConnector(WebSiteConnector.class);

    try {
        final Alert alert = webSiteConnector.getDriver().switchTo().alert();
        final String text = alert.getText();
        variableStore.set(variableName, text);

        LOGGER.info(LEARNER_MARKER, "Save text '{}' from alert to variable '{}' (ignoreFailure: {}, negated: {}).",
                    text, variableName, ignoreFailure, negated);

        return getSuccessOutput();
    } catch (NoAlertPresentException e) {
        LOGGER.info(LEARNER_MARKER, "Failed to get text from alert (ignoreFailure: {}, negated: {}).",
                    ignoreFailure, negated);

        return getFailedOutput();
    }
}
项目:alex    文件:AlertSendKeysAction.java   
@Override
protected ExecuteResult execute(final WebSiteConnector connector) {
    try {
        final Alert alert = connector.getDriver().switchTo().alert();
        alert.sendKeys(insertVariableValues(text));

        LOGGER.info(LEARNER_MARKER, "Send text '{}' to prompt window (ignoreFailure: {}, negated: {}).",
                    text, ignoreFailure, negated);

        return getSuccessOutput();
    } catch (NoAlertPresentException | ElementNotSelectableException e) {
        LOGGER.info(LEARNER_MARKER, "Failed to send text '{}' to prompt window (ignoreFailure: {}, negated: {}).",
                    text, ignoreFailure, negated);

        return getFailedOutput();
    }
}
项目:kurento-tutorial-java    文件:One2OneCallAdvIT.java   
private void waitForIncomingCallDialog(WebDriver driver)
        throws InterruptedException {
    int i = 0;
    for (; i < TEST_TIMEOUT; i++) {
        try {
            driver.switchTo().alert();
            break;
        } catch (NoAlertPresentException e) {
            Thread.sleep(1000);
        }
    }
    if (i == TEST_TIMEOUT) {
        throw new RuntimeException("Timeout (" + TEST_TIMEOUT
                + " seconds) waiting for incoming call");
    }
}
项目:kurento-tutorial-java    文件:One2OneCallIT.java   
private void waitForIncomingCallDialog(WebDriver driver)
        throws InterruptedException {
    int i = 0;
    for (; i < TEST_TIMEOUT; i++) {
        try {
            driver.switchTo().alert();
            break;
        } catch (NoAlertPresentException e) {
            Thread.sleep(1000);
        }
    }
    if (i == TEST_TIMEOUT) {
        throw new RuntimeException("Timeout (" + TEST_TIMEOUT
                + " seconds) waiting for incoming call");
    }
}
项目:teammates    文件:AdminActivityLogPageUiTest.java   
private void testSanitization() {
    ______TS("safe against injection from admin search page");

    AdminSearchPage searchPageForInjection = logPage
            .navigateTo(createUrl(Const.ActionURIs.ADMIN_SEARCH_PAGE))
            .changePageType(AdminSearchPage.class);

    String injectedScript = "Test Injected Script<script>alert('This is not good.');</script>";
    searchPageForInjection.inputSearchContent(injectedScript);
    searchPageForInjection.clickSearchButton();
    searchPageForInjection.waitForPageToLoad();

    logPage.navigateTo(createUrl(Const.ActionURIs.ADMIN_ACTIVITY_LOG_PAGE));
    logPage.waitForPageToLoad();

    try {
        browser.driver.switchTo().alert();
        signalFailureToDetectException("Script managed to get injected");
    } catch (NoAlertPresentException e) {
        // this is what we expect, since we expect the script injection to fail
    }
}
项目:WMarket    文件:SeleniumIT.java   
@Before
public void setUp() {

    try {
        // Close alerts if present
        driver.switchTo().alert().accept();
    } catch (NoAlertPresentException ex) {
        // Nothing to do...
    }

    // Restart cookies and browser
    driver.manage().deleteAllCookies();
    driver.get("about:blank");

    startMockServer();
}
项目:automation-test-engine    文件:MultiWindowsHandler.java   
/**
 * Close window.
 *
 * @param winHandle
 *            the win handle
 * @throws BrowserUnexpectedException 
 */
public void closeWindow(String winHandle) throws BrowserUnexpectedException {
    BrowserWindow closingWindow = getWindowByHandle(winHandle);
    if (null == closingWindow) {
        // if (winHandle.equals(getWindowOnFocusHandle())) {
        // getDriver().close();
        // } else {
        // getDriver().switchTo().window(winHandle);
        // getDriver().close();
        // }
        throw GlobalUtils.createNotInitializedException("windows");
    } else {
        closingWindow.close();
        try {
            // test if there is alert. if no, refresh windows list
            checkCloseWindowAlert(closingWindow.getWindowHandle());

            closingWindow.setClosed(false);
        } catch (NoAlertPresentException noAlert) {
            if (getNumberOfOpenWindows() > 0)
                refreshWindowsList(getDriver(), false);
        }
    }

}
项目:automation-test-engine    文件:MultiWindowsHandler.java   
private void checkCloseWindowAlert(String winh)
        throws NoAlertPresentException {
    try {
        Alert alt = getDriver().switchTo().alert();
        if (alt == null)
            throw GlobalUtils.createInternalError("web driver");
        PopupPromptDialog aDialog = new PopupPromptDialog(getDriver(), alt,
                alerts.size());
        aDialog.setClosingWindowHandle(winh);
        alerts.add(aDialog);
    } catch (UnreachableBrowserException error) {
        if (getNumberOfOpenWindows() > 0)
            throw GlobalUtils
                    .createInternalError("ATE multi windows handler", error);
    } catch (UnsupportedOperationException e) {

            throw GlobalUtils
                    .createInternalError("Driver doesn't support alert handling yet", e);
    } catch (NoSuchWindowException windClosedAlready) {
        //do nothing if window closed without alert dialog intervention. for example in Chrome.
        throw new NoAlertPresentException(windClosedAlready);
    }
}
项目: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");
}
项目: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);
    }
}
项目: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;
    }
}
项目:KITE    文件:IceConnectionTest.java   
/**
 * Opens the APPRTC_URL and clicks 'confirm-join-button'.
 */
private void takeAction() {
  Random rand = new Random(System.currentTimeMillis());
  long channel = Math.abs(rand.nextLong());

  for (WebDriver webDriver : this.getWebDriverList()) {
    webDriver.get(APPRTC_URL + channel);
    try {
      webDriver.switchTo().alert().accept();
    } catch (NoAlertPresentException e) {
      logger.warn(e.getLocalizedMessage());
    }
    webDriver.findElement(By.id("confirm-join-button")).click();
  }
}
项目:chr-krenn-fhj-ws2017-sd17-pse    文件:PageObject.java   
boolean isAlertPresent() {
    try {
        getDriver().switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:Verifications.java   
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;
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:CommonMethods.java   
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;
    }
}
项目:Cognizant-Intelligent-Test-Scripter    文件:General.java   
public boolean isAlertPresent() {
    try {
        Driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.OFF, null, e);
        return false;
    }
}
项目:willtest    文件:JavascriptAlert.java   
@Override
protected void onError(Description description, Throwable testFailure) throws Throwable {
    super.onError(description, testFailure);
    WebDriver webDriver = seleniumProvider.getWebDriver();
    try {
        Alert alert = webDriver.switchTo().alert();
        testFailure.addSuppressed(new RuntimeException("Unexpected alert with text: '" + alert.getText() + "'!"));
    } catch (NoAlertPresentException ignored) {
    } finally {
        webDriver.switchTo().defaultContent();
    }
}
项目:Java_Good    文件:HelperBase.java   
public boolean isAlertPresent() {
    try {
        wd.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:Java_Good    文件:HelperBase.java   
public boolean isAlertPresent() {
    try {
        wd.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目: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();
  }
}
项目:bobcat    文件:ClosingAwareWebDriverWrapperTest.java   
private void setUp(boolean maximize, boolean reusable, boolean mobile) {
  testedObject = spy(
      new ClosingAwareWebDriverWrapper(webDriver, frameSwitcher, maximize, reusable, 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();
}
项目: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");
}
项目: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");
}
项目: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;
    }
}
项目: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;
    }
}
项目:java_pft    文件:HelperBase.java   
public boolean isAlertPresent() {
  try {
    wd.switchTo().alert();
    return true;
  } catch (NoAlertPresentException e) {
    return false;
  }
}
项目:java_pft    文件:HelperBase.java   
public boolean isAlertPresent() {
  try {
    wd.switchTo().alert();
    return true;
  } catch (NoAlertPresentException e) {
    return false;
  }
}
项目:SeleniumCucumber    文件:AlertHelper.java   
public boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        oLog.info("true");
        return true;
    } catch (NoAlertPresentException e) {
        // Ignore
        oLog.info("false");
        return false;
    }
}
项目:JAVA_rep1    文件:HelperBase.java   
public  boolean isAlertPresent() {
    try {
        wd.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:JAVA_rep1    文件:HelperBase.java   
public  boolean isAlertPresent() {
    try {
        wd.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:JAVA_rep1    文件:HelperBase.java   
public  boolean isAlertPresent() {
    try {
        wd.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:easyium-java    文件:WebDriverAlertPresentCondition.java   
@Override
public boolean occurred() {
    try {
        webDriver.seleniumWebDriver().switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}
项目:bdd-test-automation-for-mobile    文件:HomeScreen.java   
public void handlePushNotificationAlert() {
    try {
        String alertText = getAppiumDriver().switchTo().alert().getText();
        logger.info(alertText);
        if (alertText.contains("Would Like to Send You Notifications Notifications may include alerts, sounds, and icon badges. These can be configured in Settings.")) {
            logger.info("Push Notification alert raised : " + getAppiumDriver().switchTo().alert().getText());
            okBtn.click();
        }
    }
    catch (NoAlertPresentException ex) {
        logger.info("Push Notification alert did not pop up");
    }
}
项目:jira-dvcs-connector    文件:RepositoriesPage.java   
public void addOrganisation(int accountType, String accountName, String url, OAuthCredentials oAuthCredentials, boolean autoSync)
{
    linkRepositoryButton.click();
    waitFormBecomeVisible();
    dvcsTypeSelect.select(dvcsTypeSelect.getAllOptions().get(accountType));
    organization.clear().type(accountName);

    switch (accountType)
    {
    case 0:
        oauthBbClientId.clear().type(oAuthCredentials.key);
        oauthBbSecret.clear().type(oAuthCredentials.secret);
        break;
    case 1:
        oauthClientId.clear().type(oAuthCredentials.key);
        oauthSecret.clear().type(oAuthCredentials.secret);
        break;
    case 2:
        urlGhe.clear().type(url);
        oauthClientIdGhe.clear().type(oAuthCredentials.key);
        oauthSecretGhe.clear().type(oAuthCredentials.secret);
        break;
    default:
        break;
    } 

    autoLinkNewRepos.click();
    addOrgButton.click();

    // dismiss any information alert
    try {
        webDriver.switchTo().alert().accept();
    } catch (NoAlertPresentException e) {
        // nothing to do
    }
}
项目:SeInterpreter-Java    文件:AlertPresent.java   
@Override
public String get(TestRun ctx) {
    try {
        ctx.driver().switchTo().alert();
        return "" + true;
    } catch (NoAlertPresentException e) {
        return "" + false;
    }
}
项目:brixen    文件:IsAlertPresent.java   
@Override
public boolean test(final WebDriver driver) {
    JavascriptExecutor executor = (JavascriptExecutor)driver;

    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException nape) {
        return false;
    }
}
项目:java_pft    文件:HelperBase.java   
public boolean isAlertPresent() {
  try {
    wd.switchTo().alert();
    return true;
  } catch (NoAlertPresentException e) {
    return false;
  }
}
项目:java_pft    文件:HelperBase.java   
public boolean isAlertPresent() {
  try {
    wd.switchTo().alert();
    return true;
  } catch (NoAlertPresentException e) {
    return false;
  }
}