/// <summary> /// Set text /// </summary> /// <param name="path"></param> /// <param name="textvalue"></param> /// <param name="value"></param> /// <returns></returns> public ActionResult SetText(string path, string textvalue, Commonenums.ElementType value) { try { IWebElement textboxobject; switch (value) { case Commonenums.ElementType.xPath: if (ElementVisibility.WaitForElementVisible(By.XPath(path))) { textboxobject = Browser.driver.FindElement(By.XPath(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } };; break; case Commonenums.ElementType.csspath: if (ElementVisibility.WaitForElementVisible(By.CssSelector(path))) { textboxobject = Browser.driver.FindElement(By.CssSelector(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } }; break; case Commonenums.ElementType.LinkText: if (ElementVisibility.WaitForElementVisible(By.LinkText(path))) { textboxobject = Browser.driver.FindElement(By.LinkText(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } }; break; case Commonenums.ElementType.IdPath: if (ElementVisibility.WaitForElementVisible(By.Id(path))) { textboxobject = Browser.driver.FindElement(By.Id(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } }; break; case Commonenums.ElementType.className: if (ElementVisibility.WaitForElementVisible(By.ClassName(path))) { textboxobject = Browser.driver.FindElement(By.ClassName(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } }; break; case Commonenums.ElementType.Name: if (ElementVisibility.WaitForElementVisible(By.Name(path))) { textboxobject = Browser.driver.FindElement(By.Name(path)); textboxobject.SendKeys(textvalue); } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not Found" } }; break; } return(new ActionResult { IsSuccess = true, ErrorMessage = "" }); } catch (StaleElementReferenceException exception) { IWebElement textboxobject = Browser.driver.FindElement(By.Id(path)); textboxobject.SendKeys(textvalue); return(new ActionResult { IsSuccess = true, ErrorMessage = exception.Message }); } catch (Exception e) { if (Screenshot.BoolScreenShotOnException) { screenPath = Screenshot.CaptureScreenWithCallStack(); } return(new ActionResult { IsSuccess = false, ErrorMessage = e.Message, Screenpath = screenPath }); } }
/// <summary> /// Click button using javascript /// </summary> /// <param name="path"></param> /// <param name="value"></param> /// <returns></returns> public ActionResult ClickButtonByLocation(string path, Commonenums.ElementType value) { try { IWebElement element; switch (value) { case Commonenums.ElementType.xPath: if (ElementVisibility.WaitForElementVisible(By.XPath(path))) { element = Browser.driver.FindElement(By.XPath(path)); if (element.Displayed && element.Enabled) { IJavaScriptExecutor jse = (IJavaScriptExecutor)Browser.driver; jse.ExecuteScript(string.Format("window.scrollTo(0, {0});", element.Location.Y)); element.Click(); } } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not found" } }; break; case Commonenums.ElementType.csspath: if (ElementVisibility.WaitForElementVisible(By.CssSelector(path))) { element = Browser.driver.FindElement(By.CssSelector(path)); if (element.Displayed && element.Enabled) { IJavaScriptExecutor jse = (IJavaScriptExecutor)Browser.driver; jse.ExecuteScript(string.Format("window.scrollTo(0, {0});", element.Location.Y)); element.Click(); } } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not found" } }; break; case Commonenums.ElementType.IdPath: if (ElementVisibility.WaitForElementVisible(By.Id(path))) { element = Browser.driver.FindElement(By.Id(path)); if (element.Displayed && element.Enabled) { IJavaScriptExecutor jse = (IJavaScriptExecutor)Browser.driver; jse.ExecuteScript(string.Format("window.scrollTo(0, {0});", element.Location.Y)); element.Click(); } } else { return new ActionResult { IsSuccess = false, ErrorMessage = "Element Not found" } }; break; } return(new ActionResult { IsSuccess = true, ErrorMessage = string.Empty }); } catch (Exception e) { if (Screenshot.BoolScreenShotOnException) { screenPath = Screenshot.CaptureScreenWithCallStack(); } return(new ActionResult { IsSuccess = false, ErrorMessage = e.Message, Screenpath = screenPath }); } }
public ActionResult VerifyElementPresent(string path, Commonenums.ElementType value) { try { Boolean IsElementVisible = false; switch (value) { case Commonenums.ElementType.xPath: if (ElementVisibility.WaitForElementVisible(By.XPath(path))) { IsElementVisible = true; } else { IsElementVisible = false; } break; case Commonenums.ElementType.LinkText: if (ElementVisibility.WaitForElementVisible(By.LinkText(path))) { IsElementVisible = true; } else { IsElementVisible = false; } break; case Commonenums.ElementType.IdPath: if (ElementVisibility.WaitForElementVisible(By.Id(path))) { IsElementVisible = true; } else { IsElementVisible = false; } break; case Commonenums.ElementType.csspath: if (ElementVisibility.WaitForElementVisible(By.CssSelector(path))) { IsElementVisible = true; } else { IsElementVisible = false; } break; } return(new ActionResult { IsSuccess = IsElementVisible, ErrorMessage = string.Empty }); } catch (Exception e) { if (Screenshot.BoolScreenShotOnException) { screenPath = Screenshot.CaptureScreenWithCallStack(); } return(new ActionResult { IsSuccess = false, ErrorMessage = e.Message, Screenpath = screenPath }); } }