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


Java Alert.sendKeys方法代碼示例

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


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

示例1: 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

示例2: execute

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

示例3: textInputAlertTest

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Test
public void textInputAlertTest() {
    driver.findElement(MobileBy.AccessibilityId("alert_views_button"))
            .click();
    driver.findElement(MobileBy.AccessibilityId("text_entry_alert_button"))
            .click();
    wait.until(ExpectedConditions.alertIsPresent());

    Alert alert = driver.switchTo().alert();
    String titleAndMessage = alert.getText();
    assertThat(titleAndMessage, is("A Short Title Is Best A message should be a short, complete sentence."));

    //input text
    String text_alert_message = "testing alert text input field";

    alert.sendKeys(text_alert_message);
    String alertTextInputField_value = driver.findElement(MobileBy.xpath("//UIAAlert//UIATextField")).getText();
    assertThat(alertTextInputField_value, is(text_alert_message));
}
 
開發者ID:Simon-Kaz,項目名稱:AppiumSauce,代碼行數:20,代碼來源:ParallelNativeIOSTest.java

示例4: AcceptPrompt

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
public void AcceptPrompt(String text) {
	
	if (!isAlertPresent())
		return;
	
	Alert alert = getAlert();
	alert.sendKeys(text);
	alert.accept();
	oLog.info(text);
}
 
開發者ID:rahulrathore44,項目名稱:SeleniumCucumber,代碼行數:11,代碼來源:AlertHelper.java

示例5: 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

示例6: 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

示例7: setCursorToLine

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * set the cursor in the specified line
 *
 * @param positionLine is the specified number line
 * @param status is expected line and column position
 */
public void setCursorToLine(int positionLine, String status) {
  loader.waitOnClosed();
  Actions action = actionsFactory.createAction(seleniumWebDriver);
  action.keyDown(Keys.CONTROL).sendKeys("l").perform();
  Alert alert =
      new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
          .until(ExpectedConditions.alertIsPresent());
  seleniumWebDriver.switchTo().alert();
  alert.sendKeys(String.valueOf(positionLine));
  alert.accept();
  action.keyUp(Keys.CONTROL).perform();
  waitLineAndColumnInLeftCompare(status);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:20,代碼來源:GitCompare.java

示例8: promptInputPressOK

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Override
public void promptInputPressOK(String inputMessage) {
	Alert alert = waitForAlert();
	alert.sendKeys(inputMessage);
	alert.accept();

}
 
開發者ID:persado,項目名稱:stevia,代碼行數:8,代碼來源:WebDriverWebController.java

示例9: promptInputPressCancel

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Override
public void promptInputPressCancel(String inputMessage) {
	Alert alert = waitForAlert();
	alert.sendKeys(inputMessage);
	alert.dismiss();

}
 
開發者ID:persado,項目名稱:stevia,代碼行數:8,代碼來源:WebDriverWebController.java

示例10: sendTextToNextAlert

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * Enters the specified text into the upcoming input alert.
 * 
 * @param text
 *            the text to be entered
 */
public void sendTextToNextAlert(String text) {
	Alert alert = driver.switchTo().alert();

	alert.sendKeys(text);
	alert.accept();
}
 
開發者ID:ludovicianul,項目名稱:selenium-on-steroids,代碼行數:13,代碼來源:WebDriverHelper.java

示例11: canHandleChainOfAlerts

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Test
public void canHandleChainOfAlerts() {
  driver().executeScript("setTimeout(function(){alert(confirm('really? ' + prompt('testin alerts')));}, 100)");
  Alert a = new WebDriverWait(driver(), 2).until(ExpectedConditions.alertIsPresent());
  Assert.assertEquals("testin alerts", a.getText());
  a.sendKeys("WAT");
  a.accept();
  a = driver().switchTo().alert();
  Assert.assertEquals("really? WAT", a.getText());
  a.dismiss();
  a = driver().switchTo().alert();
  Assert.assertEquals("false", a.getText());
  a.dismiss();
}
 
開發者ID:selendroid,項目名稱:selendroid,代碼行數:15,代碼來源:AlertHandlingTest.java

示例12: handleExpectedPopups

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
/**
 * <b>Note:</b> For internal use only
 */
public void handleExpectedPopups() {

    while (!expectedPopupsQueue.isEmpty()) {

        IExpectedPopup expectedPopup = expectedPopupsQueue.poll();
        if (expectedPopup instanceof ExpectedAlert) {

            ExpectedAlert expectedAlert = (ExpectedAlert) expectedPopup;

            new RealHtmlElementState(new RealHtmlAlert(this)).waitToBecomeExisting();

            Alert alert = getAlert();
            if (expectedAlert.expectedText != null
                && !expectedAlert.expectedText.equals(alert.getText())) {

                throw new VerificationException("The expected alert message was: '"
                                                + expectedAlert.expectedText
                                                + "', but actually it is: '" + alert.getText() + "'");
            }
            alert.accept();
        } else if (expectedPopup instanceof ExpectedPrompt) {

            ExpectedPrompt expectedPrompt = (ExpectedPrompt) expectedPopup;

            new RealHtmlElementState(new RealHtmlPrompt(this)).waitToBecomeExisting();

            Alert prompt = getAlert();
            if (expectedPrompt.expectedText != null
                && !expectedPrompt.expectedText.equals(prompt.getText())) {

                throw new VerificationException("The expected prompt text was: '"
                                                + expectedPrompt.expectedText
                                                + "', but actually it is: '" + prompt.getText() + "'");
            }
            if (expectedPrompt.clickOk) {
                prompt.sendKeys(expectedPrompt.promptValueToSet);
                prompt.accept();
            } else {
                prompt.dismiss();
            }

        } else if (expectedPopup instanceof ExpectedConfirm) {

            ExpectedConfirm expectedConfirm = (ExpectedConfirm) expectedPopup;

            new RealHtmlElementState(new RealHtmlConfirm(this)).waitToBecomeExisting();

            Alert confirm = getAlert();
            if (expectedConfirm.expectedText != null
                && !expectedConfirm.expectedText.equals(confirm.getText())) {

                throw new VerificationException("The expected confirmation message was: '"
                                                + expectedConfirm.expectedText
                                                + "', but actually it is: '" + confirm.getText() + "'");
            }

            if (expectedConfirm.clickOk) {
                confirm.accept();
            } else {
                confirm.dismiss();
            }
        }
        UiEngineUtilities.sleep();
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:69,代碼來源:AbstractRealBrowserDriver.java

示例13: _executeStep

import org.openqa.selenium.Alert; //導入方法依賴的package包/類
@Override
public boolean _executeStep( Page pageObject, WebDriver webDriver, Map<String, Object> contextMap, Map<String, PageData> dataMap, Map<String, Page> pageMap, SuiteContainer sC, ExecutionContextTest executionContext )
{
	try
	{
		WebDriverWait alertWait = new WebDriverWait( webDriver, 5 );
		Alert currentAlert = alertWait.until( new Function<WebDriver,Alert>(){
		    @Override
		    public Alert apply( WebDriver t )
		    {
		        return ExpectedConditions.alertIsPresent().apply( t );
		        
		    }
		} );
   		
   		if ( getContext() != null && !getContext().isEmpty() )
   		    contextMap.put( getContext(), currentAlert.getText() );
   		
   		switch( ALERT_TYPE.valueOf( getName() ) )
   		{
   		    case ACCEPT:
   		        currentAlert.accept();
   		        break;
   		        		        
   		    case DISMISS:
   		        currentAlert.dismiss();
   		        break;
   		        
   		    case SEND_KEYS:
   		        currentAlert.sendKeys( getParameterValue( getParameterList().get( 0 ), contextMap, dataMap, executionContext.getxFID() ) + "" );
   		        currentAlert.accept();
   		        break;

   		    case AUTHENTICATE:
   		        currentAlert.authenticateUsing( new UserAndPassword(  getParameterValue( getParameterList().get( 0 ), contextMap, dataMap, executionContext.getxFID() ) + "",  getParameterValue( getParameterList().get( 1 ), contextMap, dataMap, executionContext.getxFID() ) + "" ) );
                   break;
   		        
   		    default:
   		        log.warn( "Unhandled Alert Type: " + getName() );
   		            
   		}
	}
	catch( NoAlertPresentException e )
	{
	    return false;
	}
	
	
	return true;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:51,代碼來源:KWSAlert.java


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