public static IWebElement GetTaggedElement <T>(PageObject page) where T : Attribute { var allElementsInPageObject = page.GetType().GetProperties(); //group all PO elements as Properties var match = allElementsInPageObject.FirstOrDefault(prop => prop.GetCustomAttributes(false).Any(attr => attr.GetType() == typeof(T))); return((IWebElement)match.GetValue(page)); //return match }
public static void WaitForScreen(this PageObject page, IWebElement element = null) { try { page.WaitForElement(element ?? CustomAttributeReader.GetTaggedElement <WaitForThisElementAttribute>(page)); } catch (NullReferenceException) { throw new NullReferenceException($"There's no default element to wait for in page object {page.GetType().Name}. Either set a default element to wait for, or pass an element to the WaitForScreen method."); } }