public static async Task <object> GetReturnValue(this IInvocation invocation, ElementObject elementObject, XPathAttribute attribute) { var element = elementObject.Element; if (element == null) { return(null); } if (invocation.IsReturning <ElementHandle[]>()) { return(await element.XPathAsync(attribute.Expression).ConfigureAwait(false)); } if (invocation.IsReturningElementObjectArray()) { var arrayType = invocation.Method.ReturnType.GetGenericArguments()[0]; var proxyType = arrayType.GetElementType(); var elementHandles = await element.XPathAsync(attribute.Expression).ConfigureAwait(false); return(ProxyFactory.ElementObjectArray(proxyType, elementObject.Page, elementHandles)); } return(null); }
public static async Task <object> GetReturnValue(this IInvocation invocation, PageObject pageObject, SelectorAttribute attribute) { var page = pageObject.Page; if (page == null) { return(null); } if (invocation.IsReturning <ElementHandle>()) { return(await page.QuerySelectorAsync(attribute.Selector).ConfigureAwait(false)); } if (invocation.IsReturning <ElementHandle[]>()) { return(await page.QuerySelectorAllAsync(attribute.Selector).ConfigureAwait(false)); } if (invocation.IsReturningElementObject()) { var proxyType = invocation.Method.ReturnType.GetGenericArguments()[0]; var elementHandle = await page.QuerySelectorAsync(attribute.Selector).ConfigureAwait(false); return(ProxyFactory.ElementObject(proxyType, page, elementHandle)); } if (invocation.IsReturningElementObjectArray()) { var arrayType = invocation.Method.ReturnType.GetGenericArguments()[0]; var proxyType = arrayType.GetElementType(); var elementHandles = await page.QuerySelectorAllAsync(attribute.Selector).ConfigureAwait(false); return(ProxyFactory.ElementObjectArray(proxyType, page, elementHandles)); } return(null); }