I am finding a hard time automating a basic UI test case. Using Selenium for the first time.
I am trying to write some UI test cases for an application which has User Login module with a username and password. After login, there can be two scenarios as usual : Successful Login and Incorrect password.
On Successful Login the Application URL changes. E.g. www.abc.com/AA to www.abc.com/BB.
On Incorrect Password, page REFRESHES once and then show an error message on the same page.
Now the problem is , I am able to open the page, enter U/N and Pswd through Selenium but I face issue after clicking 'Login' button when page redirect happens/refreshes.
Webdriver is unable to find any element on the page. I have already checked there is no IFrame on the page.
I am using C# Selenium Web Driver in a .net Console application. Citing the code for refrnce:
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
};
var driver = new InternetExplorerDriver("www.abc.com/AA", options);
driver.Navigate();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var username = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("userName"));
});
username.SendKeys("User1");
var password = driver.FindElement(By.Id("userPwd"));
password.SendKeys("Password@123");
// Login button pressed in the next line
password.SendKeys(Keys.Enter);
//WAIT FOR RESULT
WebDriverWait waiter = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
// This below line Shows error "Unable to find Element..."
IWebElement categoryList = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Id("SAMPLE-DROPDOWN-ID"));
});
categoryList.SendKeys("1");