use of org.openqa.selenium.Alert in project keycloak by keycloak.
the class WebAuthnRegisterPage method registerWebAuthnCredential.
public void registerWebAuthnCredential(String authenticatorLabel) {
if (!isRegisterAlertPresent(ALERT_DEFAULT_TIMEOUT)) {
throw new TimeoutException("Cannot register Security Key due to missing prompt for registration");
}
Alert promptDialog = driver.switchTo().alert();
promptDialog.sendKeys(authenticatorLabel);
promptDialog.accept();
waitForPageToLoad();
}
use of org.openqa.selenium.Alert in project selenium_java by sergueik.
the class SeleniumEasyTest method alertPromptTest.
@Test(enabled = true)
public void alertPromptTest() {
// wrong selector
String buttonText = "Click for Prompt Box";
String buttonSelector = String.format("//*[@id='easycont']//div[@class='panel-heading'][contains(normalize-space(.), '%s')]/..//button[contains(normalize-space(.), '%s')]", "Java Script Alert Box", buttonText);
try {
WebElement buttonElement = wait.until(new ExpectedCondition<WebElement>() {
Predicate<WebElement> textCheck = _element -> {
String _text = _element.getText();
System.err.format("in filter: Text: \"%s\" expecting : \"%s\"\n", _text, buttonText);
return (Boolean) (_text.contains(buttonText));
};
@Override
public WebElement apply(WebDriver d) {
System.err.println("Locating " + buttonSelector);
Optional<WebElement> e = d.findElements(By.xpath(buttonSelector)).stream().filter(textCheck).findFirst();
return (e.isPresent()) ? e.get() : (WebElement) null;
}
});
System.err.println("Acting on: " + buttonElement.getAttribute("outerHTML"));
highlight(buttonElement);
flash(buttonElement);
buttonElement.click();
sleep(1000);
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
verificationErrors.append("Exception: " + e.toString());
}
try {
// fill the data in the alert
Alert alert = driver.switchTo().alert();
System.err.println("In alert " + alert.toString());
alert.sendKeys("Harry Potter");
alert.accept();
} catch (NoAlertPresentException ex) {
// Alert not present - ignore
} catch (WebDriverException ex) {
System.err.println("Alert was not handled : " + ex.getStackTrace().toString());
return;
}
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("prompt-demo")));
assertThat(wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("prompt-demo")))).getText(), is(equalTo("You have entered 'Harry Potter' !")));
}
use of org.openqa.selenium.Alert in project devonfw-testing by devonfw.
the class WindowUtils method closeAlertIfPresent.
/**
* Checks if Alert Pop Up was displayed and dismiss it if shown.
*
* @return true if alert was dismissed, false otherwise
* @author
*/
public static boolean closeAlertIfPresent() {
try {
Alert alert = BasePage.getDriver().switchTo().alert();
alert.dismiss();
BFLogger.logDebug("Alert dismissed.");
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
use of org.openqa.selenium.Alert in project OpenOLAT by OpenOLAT.
the class QTI12Page method endTest.
public QTI12Page endTest() {
By endBy = By.cssSelector("div.o_button_group_right a");
OOGraphene.waitElement(endBy, 5, browser);
browser.findElement(endBy).click();
// accept and go further
Alert alert = browser.switchTo().alert();
alert.accept();
OOGraphene.waitAndCloseBlueMessageWindow(browser);
return this;
}
use of org.openqa.selenium.Alert in project java-client by appium.
the class BaseListenerTest method assertThatAlertListenerWorks.
protected boolean assertThatAlertListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) {
try {
Alert alert = driver.switchTo().alert();
alert.accept();
alert.dismiss();
alert.sendKeys("Keys");
assertThat(listener.messages, contains(prefix + "Attempt to accept alert", prefix + "The alert was accepted", prefix + "Attempt to dismiss alert", prefix + "The alert was dismissed", prefix + "Attempt to send keys to alert", prefix + "Keys were sent to alert"));
return true;
} finally {
listener.messages.clear();
}
}
Aggregations