Search code examples
javaseleniummodal-dialogbootstrap-modalalert

Using 'Alert' Interface in Selenium Java for alert conformation not working as expected


I used below selenium codes to click "OK" alert box, But It is not identifying, I dont knw wht's the reason, Can anyone help to solve this Issue ?

Element image:

enter image description here

Code trials:

 Alert click_on_update_button_Htwelveyes = driver.switchTo().alert();
    click_on_update_button_Htwelveyes.accept();
}

Console Output:

    org.openqa.selenium.NoAlertPresentException: no such alert
(Session info: chrome=103.0.5060.134)

Solution

  • Alert

    An alert box is used if the user wants to make sure information comes through to the user. The user will have to click on OK to agree or Cancel to deny the information.

    Alert_Ok_Cancel


    This usecase

    The following element doesn't seems to be an alert but a Modal Dialog Box :

    HLR

    In such cases you need to locate the element with the Modal Dialog Box to locate the element with text as Yes or No and invoke click() on the respective element of youe choice.