On my web page, we are filling form , there we are selecting UserName from drop-down, selecting Project from drop-down then selecting Role from radio button, then applying Role by selecting from drop-down
then clicking on apply button,
After that we are receiving alert pop up for like user is added.
I am adding Code to handle alert pop
Driver.SwitchTo().Alert().Accept();
I am getting below error:-
Assert.Fail failed. OpenQA.Selenium.UnhandledAlertException: unexpected alert open: {Alert text : Role added successfully.}
And My Test case is failing
(Session info: chrome=121.0.6167.86) at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.GetScreenshot() at UserManagement_Automation_Test_Suite.BaseClasses.ScreenShots.Take(String fileName, String floderName) in C:\UserManagement_Automation_Test_Suite\UserManagement_Automation_Test_Suite\BaseClasses\ScreenShots.cs:line 60 at UserManagement_Automation_Test_Suite.TestCases.TS_User_Management_0012ManageUserRoles.Action_01() in C:\UserManagement_Automation_Test_Suite\UserManagement_Automation_Test_Suite\TestCases\TS_User_Management_0012ManageUserRoles.cs:line 30
Driver.SwitchTo().Alert().Accept();
public static void AlertPopUp()
{
string text = ObjectRepository.Driver.SwitchTo().Alert().Text;
Assert.IsTrue(text.Contains("User added successfully with email: [email protected]."));
}
Expecting without failing I should be able to close or click on OK button.