/// <summary> /// This method clear the text from a control /// </summary> /// <param name="pageName"></param> /// <param name="locatorName"></param> /// <param name="values"></param> public static void ClearText(string pageName, string locatorName, params String[] values) { By element = null; if (values.Length == 0) { element = ElementLocator.GetLocator(pageName, locatorName); } else { element = ElementLocator.GetLocator(pageName, locatorName, values); } if (element != null) { try { wait.Until(WaitHelper.ExpectedConditions.PresenceOfAllElementsLocatedBy(element)); JavaScriptKeywords.HighlightElement(driver.FindElement(element)); driver.FindElement(element).Clear(); Report.Pass(locatorName + "Cleared"); log.Info(locatorName + "Cleared"); } catch (WebDriverException wd) { Report.Fail("Exception on the element " + locatorName + " " + wd.Message); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); } } else { Report.Fail(locatorName + " not found"); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); } }
/// <summary> /// This method click on a control /// </summary> /// <param name="pageName"></param> /// <param name="locatorName"></param> /// <param name="values"></param> public static void Click(string pageName, string locatorName, params string[] values) { By element = null; if (values.Length == 0) { element = ElementLocator.GetLocator(pageName, locatorName); } else { element = ElementLocator.GetLocator(pageName, locatorName, values); } if (element != null) { //try //{ wait.Until(WaitHelper.ExpectedConditions.ElementToBeClickable(element)); JavaScriptKeywords.HighlightElement(driver.FindElement(element)); driver.FindElement(element).Click(); Report.Pass("Clicked On " + locatorName); log.Info("Clicked On " + locatorName); //}catch(WebDriverException wd) //{ // Report.Fail("Exception on the element "+ locatorName+" "+wd.Message); // log.Error(TestContext.CurrentContext.Test.MethodName + " Exception " + wd.Message); //} } else { Report.Fail(locatorName + " not found"); log.Error(TestContext.CurrentContext.Test.MethodName + " " + locatorName + " not found"); } }
/// <summary> /// Gets a value indicating whether or not this element is visible. /// When expected result is false /// </summary> /// <param name="pageName"></param> /// <param name="locatorName"></param> /// <param name="values"></param> /// <returns></returns> public static Boolean IsElementNotVisible(string pageName, string locatorName, params String[] values) { bool exists = false; By element = null; if (values.Length == 0) { element = ElementLocator.GetLocator(pageName, locatorName); } else { element = ElementLocator.GetLocator(pageName, locatorName, values); } if (element != null) { try { IWebElement el = driver.FindElement(element); exists = el.Displayed; if (exists == true) { JavaScriptKeywords.HighlightElement(el); Report.Fail("Element " + locatorName + " Exists on screen: " + exists.ToString()); log.Error("Element" + locatorName + " Exists on screen: " + exists.ToString()); } else { Report.Pass("Element " + locatorName + " Exists on screen: " + exists.ToString()); log.Info("Element" + locatorName + " Exists on screen: " + exists.ToString()); } } catch (NoSuchElementException e) { Report.Pass("Element " + locatorName + " exists on screen: " + exists.ToString()); log.Info("Element" + locatorName + " Exists on screen: " + exists.ToString()); } catch (Exception e) { Report.Fail("Locator name : " + locatorName + " , " + e.Message); log.Error("Locator name : " + locatorName + " , " + e.Message); } } return(exists); }