/// <summary> /// This extension method will close all the workflow window, better to place this at the end of script execution /// </summary> /// <param name="webActions"></param> //public static void CloseAllWorkFlowWindows(this WebActions webActions) //{ // retry: // IReadOnlyCollection<string> allHandles = webActions.GetWindowHandles(); // try // { // foreach (string handle in allHandles) // { // webActions.SwitchToWindow(handle); // if (webActions.GetWindowTitle().Contains(CommonObjects.wndWorkFlowTitle)) // { // webActions.CloseBrowser(); // } // } // webActions.SwitchToFirstOrDefaultWindow(); // } // catch (Exception ex) // { // System.Threading.Thread.Sleep(3000); // goto retry; // } //} /// <summary> /// Generic extension method to get the x y co ordinates of the web element /// </summary> /// <param name="webActions"></param> /// <param name="ByLocater"></param> /// <returns></returns> public static Tuple <int, int> GetElementXYCoordinates(this WebActions webActions, By ByLocater) { int x = webActions.FindElement(ByLocater).Location.X; int y = webActions.FindElement(ByLocater).Location.Y; return(Tuple.Create(x, y)); }
/// <summary> /// /// </summary> /// <param name="webActions"></param> /// <param name="rowNumber"></param> public static string ClickTableAtRowAndCellNumber(this WebActions webActions, By tableLocater, int rowNumber, int cellNumber) { string InvestigationID = string.Empty; IList <IWebElement> lstTrElem = webActions.FindElement(tableLocater).FindElements(By.TagName("tr")); IWebElement row = lstTrElem[rowNumber];//for selecting first row IList <IWebElement> cells = row.FindElements(By.TagName("td")); IWebElement cell = cells[cellNumber]; InvestigationID = cell.Text; cell.Click(); System.Threading.Thread.Sleep(3000); return(InvestigationID); }
/// <summary> /// generic method to search and match string and click on any table row /// </summary> /// <param name="webActions"></param> /// <param name="tableLocater"></param> /// <param name="searchCriteria"></param> public static void ClickTableRowWithSearchCriteria(this WebActions webActions, By tableLocater, string searchCriteria) { IList <IWebElement> lstTrElem = webActions.FindElement(tableLocater).FindElements(By.TagName("tr")); System.Threading.Thread.Sleep(3000); IWebElement row = lstTrElem.Where(item => item.Text.Contains(searchCriteria)).FirstOrDefault(); System.Threading.Thread.Sleep(1000); IList <IWebElement> cells = row.FindElements(By.TagName("td")); IWebElement cell = cells.Where(item => item.Text.Contains(searchCriteria)).FirstOrDefault(); cell.Click(); System.Threading.Thread.Sleep(3000); }