本文整理汇总了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;
}
示例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();
}
}
示例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));
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例8: promptInputPressOK
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public void promptInputPressOK(String inputMessage) {
Alert alert = waitForAlert();
alert.sendKeys(inputMessage);
alert.accept();
}
示例9: promptInputPressCancel
import org.openqa.selenium.Alert; //导入方法依赖的package包/类
@Override
public void promptInputPressCancel(String inputMessage) {
Alert alert = waitForAlert();
alert.sendKeys(inputMessage);
alert.dismiss();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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;
}