I have an angularjs webpage that prompts when I perform certain action on the page. The code should ignore and continue if there is no prompt, but if a prompt appears then ensure that the javascript prompt is accepted.
When I use firebug, I get the following property of the element. /html/body/div[2]
The div[number] changes as and when I go to this page.I am not able to use the same in XPath as everytime the test case is executed, the div element would change. Also the div has an attribute of tabindex = -1.
bool status = false;
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
IWebElement alert;
if (wait.Until(ExpectedConditions.InvisibilityOfElementLocated((By.XPath("/html/body/div[2]")
{
Console.WriteLine("I am in if loop");
status = false;
}
else
{
Console.WriteLine("I am in else loop");
alert = Browser.Driver.FindElement(By.XPath("/html/body/div[2]"));
((IJavaScriptExecutor)webDriver).ExecuteScript("arguments[0].click()", alert);
status = true;
}
return status;How do I handle such a dialog box(refer to the attached angularjs-image.png) and ensure that the same is accepted when it appears.
Thanks.