Inspiron
Inspiron

Reputation: 51

Capture the Alert Message text , which is displayed in a TextBox and in editable format

try{
WebDriverWait wait = new WebDriverWait(driver,8(;
if (wait.until(ExpectedConditions.alertIsPresent())== null)
{
Alert alert = driver.switchTo().alert();
String aamessage = alert.getText();
if(aamessage.equals("invoked")) /// this text is in input box in Alert pop up, I am able to edit this message in alert pop up.
{
alert.accept();
}
else
{
syso("no alerts");
}
}
catch(unHandledAlertException f)
{}
catch(NoAlertPresentException h)
{}

To get the text message which is in Input box, i tried this. BUt code not getting that message. Do we have any thing in specific in such cases.

Also in few functionalities, where the alert pop-ups are displayed, I handled it and used alert.accept(). But still the exception "unhandledalert" is displayed in the console. How to avoid this.

Upvotes: 0

Views: 260

Answers (1)

SeleniumUser
SeleniumUser

Reputation: 4177

Check this :

Alert alert = driver.switchTo().alert();
WebElement element=driver.findElement(By.id("input id"));

System.out.println("Input text value:- " +element.getAttribute("value"));

Upvotes: 1

Related Questions