@@ -56,8 +56,16 @@ public async Task<ActionResult> FindElementsFromElement([FromRoute] string sessi
5656
5757 private static async Task < ActionResult > FindElementFrom ( Func < AutomationElement > startNode , FindElementRequest findElementRequest , Session session )
5858 {
59- var condition = GetCondition ( session . Automation . ConditionFactory , findElementRequest . Using , findElementRequest . Value ) ;
60- AutomationElement ? element = await Wait . Until ( ( ) => startNode ( ) . FindFirstDescendant ( condition ) , element => element != null , session . ImplicitWaitTimeout ) ;
59+ AutomationElement ? element ;
60+ if ( findElementRequest . Using == "xpath" )
61+ {
62+ element = await Wait . Until ( ( ) => startNode ( ) . FindFirstByXPath ( findElementRequest . Value ) , element => element != null , session . ImplicitWaitTimeout ) ;
63+ }
64+ else
65+ {
66+ var condition = GetCondition ( session . Automation . ConditionFactory , findElementRequest . Using , findElementRequest . Value ) ;
67+ element = await Wait . Until ( ( ) => startNode ( ) . FindFirstDescendant ( condition ) , element => element != null , session . ImplicitWaitTimeout ) ;
68+ }
6169
6270 if ( element == null )
6371 {
@@ -73,8 +81,16 @@ private static async Task<ActionResult> FindElementFrom(Func<AutomationElement>
7381
7482 private static async Task < ActionResult > FindElementsFrom ( Func < AutomationElement > startNode , FindElementRequest findElementRequest , Session session )
7583 {
76- var condition = GetCondition ( session . Automation . ConditionFactory , findElementRequest . Using , findElementRequest . Value ) ;
77- AutomationElement [ ] elements = await Wait . Until ( ( ) => startNode ( ) . FindAllDescendants ( condition ) , elements => elements . Length > 0 , session . ImplicitWaitTimeout ) ;
84+ AutomationElement [ ] elements ;
85+ if ( findElementRequest . Using == "xpath" )
86+ {
87+ elements = await Wait . Until ( ( ) => startNode ( ) . FindAllByXPath ( findElementRequest . Value ) , elements => elements . Length > 0 , session . ImplicitWaitTimeout ) ;
88+ }
89+ else
90+ {
91+ var condition = GetCondition ( session . Automation . ConditionFactory , findElementRequest . Using , findElementRequest . Value ) ;
92+ elements = await Wait . Until ( ( ) => startNode ( ) . FindAllDescendants ( condition ) , elements => elements . Length > 0 , session . ImplicitWaitTimeout ) ;
93+ }
7894
7995 if ( elements . Length == 0 )
8096 {
0 commit comments