當前位置: 首頁>>代碼示例>>Java>>正文


Java Alert.dismiss方法代碼示例

本文整理匯總了Java中org.openqa.selenium.Alert.dismiss方法的典型用法代碼示例。如果您正苦於以下問題:Java Alert.dismiss方法的具體用法?Java Alert.dismiss怎麽用?Java Alert.dismiss使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openqa.selenium.Alert的用法示例。


在下文中一共展示了Alert.dismiss方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@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();
    }
}
 
開發者ID:LearnLib,項目名稱:alex,代碼行數:26,代碼來源:AlertAcceptDismissAction.java

示例2: open

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Override
public void open()
{
	String paramUrl = paramTranslate(getUrl());
	
	engine.openUrl(paramUrl);
	
	try
	{
		engine.computeToolbarHeight();
	}
	catch(UnhandledAlertException e)
	{
		Alert alert = engine.getDriver().switchTo().alert();
		if(alert != null)
		{
			alert.dismiss();

			engine.computeToolbarHeight();
		}
	}
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:23,代碼來源:WebPage.java

示例3: onCommand

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected Object onCommand(Context context) {
    Alert alert = getSession().switchTo().alert();
    String text = alert.getText();

    Object value = getValue();
    if (value != null) {
        alert.sendKeys(value.toString());
    }

    if ("ok".equalsIgnoreCase(click)) {
        alert.accept();
    } else if ("close".equalsIgnoreCase(click)) {
        alert.dismiss();
    }

    return text;
}
 
開發者ID:niuxuetao,項目名稱:paxml,代碼行數:22,代碼來源:AlertTag.java

示例4: closeAlertAndGetItsText

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
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;
    }
}
 
開發者ID:hiroshitoda,項目名稱:Selenium-sample-with-Jenkins,代碼行數:22,代碼來源:SimpleTest.java

示例5: confirmAction

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@RobotKeyword("Dismisses currently shown confirmation dialog and returns its message.\r\n" + 
        "\r\n" + 
        "By default, this keyword chooses 'OK' option from the dialog. If 'Cancel' needs to be chosen, keyword `Choose Cancel On Next Confirmation` must be called before the action that causes the confirmation dialog to be shown.\r\n" + 
        "\r\n" + 
        "Example:\r\n" + 
        " | Click Button | Send |  | # Shows a confirmation dialog | \r\n" + 
        " | ${message}= | Confirm Action |  | # Chooses Ok | \r\n" + 
        " | Should Be Equal | ${message} | Are your sure? | # Check dialog message | \r\n" + 
        " | Choose Cancel On Next Confirmation |  |  | # Choose cancel on next Confirm Action | \r\n" + 
        " | Click Button | Send |  | # Shows a confirmation dialog | \r\n" + 
        " | Confirm Action |  |  | # Chooses Cancel |")
public String confirmAction() {
	try {
		Alert alert = browserManagement.getCurrentWebDriver().switchTo().alert();
		String text = alert.getText().replace("\n", "");
		if (acceptOnNextConfirmation) {
			alert.accept();
		} else {
			alert.dismiss();
		}
		acceptOnNextConfirmation = acceptOnNextConfirmationDefault;
		return text;
	} catch (WebDriverException wde) {
		throw new SeleniumLibraryNonFatalException("There were no alerts");
	}
}
 
開發者ID:Hi-Fi,項目名稱:robotframework-seleniumlibrary-java,代碼行數:27,代碼來源:JavaScript.java

示例6: takeScreenshot

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
public synchronized void takeScreenshot(final String errorMessage, final String testName) {
        try {
//This probably could be used someday (do not delete)
//            int jsErrorNumber = JavaScriptError.readErrors(getWebDriver()).size();
//            printStrings(image, removeNL(testName, errorMessage, "The following number of JS errors appeared during the test: " + jsErrorNumber));
            BufferedImage image = new OurScreenshot().fullPage().getImage();
            printStrings(image, removeNL(testName, errorMessage));

            final String pathName = getFilenameFor(testName);
            final File screenShotWithProjectPath = new File(pathName);
            ImageIO.write(image, "png", screenShotWithProjectPath);
            addScreenShotPathForTest(getOriginalTestName(testName), screenShotWithProjectPath.getPath(), errorMessage);

            attachScreenShotToAllure(errorMessage, testName, screenShotWithProjectPath);

//VE path below works for TestNG (do not delete)
//            String pathToImage = "../../ws/test-reports/test-classes/" + screenShotWithProjectPath.getName();
//VE path below works for ReportNG
            String pathToImage = "../../test-reports/test-classes/" + screenShotWithProjectPath.getName();

            Reporter.log("<br/><a href='" + pathToImage + "' target='_blank'> <img src='" + pathToImage + "' height='100' width='100'/> </a><br/>");

        } catch (IOException e) {
            LOGGER.error("IOException occurs", e);
        } catch (UnhandledAlertException alertException) {
            Alert alert = getWebDriver().switchTo().alert();
            String alertText = alert.getText();
            LOGGER.error("*****ERROR***** Unexpected Alert appeared. Alert text " + alertText);
            alert.dismiss();
            takeScreenshot(errorMessage, testName);
        }
    }
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:33,代碼來源:Screenshoter.java

示例7: closeAlertAndGetItsText

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
String closeAlertAndGetItsText() {
	try {
		Alert alert = getDriver().switchTo().alert();
		String alertText = alert.getText();
		if (acceptNextAlert) {
			alert.accept();
		} else {
			alert.dismiss();
		}
		return alertText;
	} finally {
		acceptNextAlert = true;
	}
}
 
開發者ID:chr-krenn,項目名稱:chr-krenn-fhj-ws2017-sd17-pse,代碼行數:15,代碼來源:PageObject.java

示例8: dismissAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
public static final void dismissAlert(){
	SeleniumWaitUtils.waitForAlert();
	Alert alert = Config.driver().switchTo().alert();
	log.info("Alert: " + alert.getText());
	alert.dismiss();
	log.info("Dismiss Alter");	
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:8,代碼來源:SeleniumUtils.java

示例9: handleAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * This method handles alert windows
 **/
public static void handleAlert(String status, WebDriver driver) {
	Alert alert = driver.switchTo().alert();
	if (status.equalsIgnoreCase("Y")) {
		alert.accept();
	} else if (status.equalsIgnoreCase("N")) {
		alert.dismiss();
	}
}
 
開發者ID:AnujDasari,項目名稱:Actitime-Framework,代碼行數:12,代碼來源:HelperManager.java

示例10: alertDismiss

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * 點擊取消按鈕
 */
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;
	}
}
 
開發者ID:zhengshuheng,項目名稱:PatatiumWebUi,代碼行數:17,代碼來源:ElementAction.java

示例11: perform

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Override
public void perform(final AlertAction action, final ScenarioExecutionContext context) {
    WebDriver driver = context.getDriver();

    // Wait for the alert
    WebDriverWait wait = new WebDriverWait(driver, getActionTimeout(action, context));
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();

    // Validate text
    String expectedAlertText = action.getText();
    String alertText = alert.getText();
    if (expectedAlertText != null && !expectedAlertText.equals(alertText)) {
        throw new AlertTextMismatchException(action.getClass(), expectedAlertText, alertText);
    }

    // Enter text (in the prompt)
    String promptInput = action.getInput();
    if (promptInput != null ) {
        alert.sendKeys(promptInput);
    }

    String confirmValue = action.getConfirm();
    try {
        if (BooleanMapper.isTrue(confirmValue)) {
            alert.accept();
        } else {
            alert.dismiss();
        }
    } catch (BooleanExpectedException e) {
        throw new BooleanExpectedException(action.getClass(), confirmValue);
    }
}
 
開發者ID:automate-website,項目名稱:jwebrobot,代碼行數:34,代碼來源:AlertActionExecutor.java

示例12: testDocSearchToAnotherViewBookmark

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Test
    /**
     * test that after doc search, navigating to people flow maintenance view does not cause Javascript errors
     * and therefore interfere with JS functionality like validation
     */
	public void testDocSearchToAnotherViewBookmark() throws Exception {
		waitAndClick("img[alt=\"doc search\"]");
		waitForPageToLoad();
		selectFrame("iframeportlet");
		waitAndClick("td.infoline > input[name=\"methodToCall.search\"]");
	//	selectFrame("relative=top");
		driver.switchTo().defaultContent();
		waitAndClickByLinkText("Main Menu");
		waitAndClickByLinkText("People Flow");
		waitForPageToLoad();
		selectFrame("iframeportlet");
		waitAndClickByLinkText("Create New");
		waitForPageToLoad();
		fireEvent("document.documentHeader.documentDescription", "focus");
		waitAndTypeByName("document.documentHeader.documentDescription", "sample description");
		fireEvent("document.documentHeader.explanation", "focus");
		waitAndTypeByName("document.documentHeader.explanation", "sample explanation");		
//		((JavascriptExecutor)driver).executeScript("document.getElementById(\"uif-cancel\").focus();");
        jGrowl("Click Cancel");
        waitAndClickByXpath("//div[@class='uif-footer clearfix']/button[contains(text(), 'Cancel')]");
		Thread.sleep(5000);
		final String text = "Form has unsaved data. Do you want to leave anyway?";
		Alert a=driver.switchTo().alert();
		assertTrue(a.getText().equals(text));
		a.dismiss();
        passed();
	}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:33,代碼來源:DocSearchToAnotherViewAft.java

示例13: dismissAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * Dismiss the javascript alert (clicking Cancel)
 *
*/
protected void dismissAlert()
{
    Alert alert = driver.switchTo().alert();
    //update is executed
    alert.dismiss();
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:11,代碼來源:WebDriverITBase.java

示例14: handleAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
public boolean handleAlert(Alert alert) {

		System.out.println("Handling alert with text " + alert.getText());
		if(alert.getText().toLowerCase().contains("hello"))
		{
			System.out.println("Trying to accept the alert");
			alert.accept();
			System.out.println("Accepted the aert successfully");
			
		}
		else if(alert.getText().toLowerCase().contains("toolsqa"))
		{
			System.out.println("Trying to type something and accept the alert");
			alert.sendKeys("Sample Yes");
			alert.dismiss();
			System.out.println("Alert dismissed successfully");
		}
		else if(alert.getText().toLowerCase().contains("pop up"))
		{
			System.out.println("Trying to dismiss this alert");
			alert.dismiss();
			System.out.println("Alert dismissed successfully");
		}
		else if(alert.getText().toLowerCase().contains("simple"))
		{
			System.out.println("This seems to be a same alert scenario, accepting the alert");
			alert.accept();
			System.out.println("Accepted the alert successfully");
	
		}
		
		System.out.println("Handled alert by accepting the alert");
		return true;
	}
 
開發者ID:toolsqa,項目名稱:OptimusPrime,代碼行數:35,代碼來源:HtmlAlertHandlers.java

示例15: dismissAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
public void dismissAlert(String... waitFor) {
	driver.switchTo().defaultContent();
	Alert alert = driver.switchTo().alert();
	alert.dismiss();
	if (waitFor != null && waitFor.length > 0) {
		setDriverWait(waitFor[0]);
	}
}
 
開發者ID:gautamsabba,項目名稱:UIFramework,代碼行數:9,代碼來源:PopupHandler.java


注:本文中的org.openqa.selenium.Alert.dismiss方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。