2525import org .labkey .test .selenium .ReclickingWebElement ;
2626import org .labkey .test .selenium .RefindingWebElement ;
2727import org .labkey .test .util .TestLogger ;
28+ import org .labkey .test .util .TextUtils ;
2829import org .labkey .test .util .selenium .WebDriverUtils ;
2930import org .openqa .selenium .By ;
3031import org .openqa .selenium .InvalidSelectorException ;
@@ -185,23 +186,30 @@ protected WebDriver getWebDriver(SearchContext context)
185186 */
186187 public static WebElement waitForAnyElement (FluentWait <? extends SearchContext > wait , final Locator ... locators )
187188 {
188- return wait . until ( new Function < SearchContext , WebElement >()
189+ try
189190 {
190- @ Override
191- public WebElement apply (SearchContext context )
191+ return wait .until (new Function <SearchContext , WebElement >()
192192 {
193- return findAnyElementOrNull (context , locators );
194- }
193+ @ Override
194+ public WebElement apply (SearchContext context )
195+ {
196+ return findAnyElementOrNull (context , locators );
197+ }
195198
196- @ Override
197- public String toString ()
198- {
199- List <String > locDescriptions = new ArrayList <>();
200- Arrays .stream (locators ).forEach (loc -> locDescriptions .add (loc .getLoggableDescription ()));
201- SearchContext searchContext = extractInputFromFluentWait (wait );
202- return String .join ("\n --OR--\n " , locDescriptions ) + (searchContext instanceof WebDriver ? "" : "\n IN: " + searchContext .toString ());
203- }
204- });
199+ @ Override
200+ public String toString ()
201+ {
202+ List <String > locDescriptions = new ArrayList <>();
203+ Arrays .stream (locators ).forEach (loc -> locDescriptions .add (loc .getLoggableDescription ()));
204+ SearchContext searchContext = extractInputFromFluentWait (wait );
205+ return String .join ("\n --OR--\n " , locDescriptions ) + (searchContext instanceof WebDriver ? "" : "\n IN: " + searchContext .toString ());
206+ }
207+ });
208+ }
209+ catch (TimeoutException e )
210+ {
211+ throw new NoSuchElementException (e .getMessage (), e );
212+ }
205213 }
206214
207215 /**
@@ -210,28 +218,34 @@ public String toString()
210218 */
211219 public static List <WebElement > waitForElements (FluentWait <? extends SearchContext > wait , final Locator ... locators )
212220 {
213- return wait . until ( new Function < SearchContext , List < WebElement >>()
221+ try
214222 {
215- @ Override
216- public List <WebElement > apply (SearchContext context )
217- {
218- List <WebElement > els = findElements (context , locators );
219- if (els .size () > 0 )
220- return els ;
221- else
222- return null ;
223- }
224-
225- @ Override
226- public String toString ()
223+ return wait .until (new Function <SearchContext , List <WebElement >>()
227224 {
228- List <String > locDescriptions = new ArrayList <>();
229- Arrays .stream (locators ).forEach (loc -> locDescriptions .add (loc .getLoggableDescription ()));
230- SearchContext searchContext = extractInputFromFluentWait (wait );
231- return String .join ("\n --OR--\n " , locDescriptions ) + (searchContext instanceof WebDriver ? "" : "\n IN: " + searchContext .toString ());
232- }
233- });
225+ @ Override
226+ public List <WebElement > apply (SearchContext context )
227+ {
228+ List <WebElement > els = findElements (context , locators );
229+ if (!els .isEmpty ())
230+ return els ;
231+ else
232+ return null ;
233+ }
234234
235+ @ Override
236+ public String toString ()
237+ {
238+ List <String > locDescriptions = new ArrayList <>();
239+ Arrays .stream (locators ).forEach (loc -> locDescriptions .add (loc .getLoggableDescription ()));
240+ SearchContext searchContext = extractInputFromFluentWait (wait );
241+ return String .join ("\n --OR--\n " , locDescriptions ) + (searchContext instanceof WebDriver ? "" : "\n IN: " + searchContext .toString ());
242+ }
243+ });
244+ }
245+ catch (TimeoutException e )
246+ {
247+ throw new NoSuchElementException (e .getMessage (), e );
248+ }
235249 }
236250
237251 public static List <WebElement > findElements (SearchContext context , final Locator ... locators )
@@ -984,7 +998,7 @@ public static String xq(String value)
984998 */
985999 private static String ns (String value )
9861000 {
987- return value . replaceAll ( " \\ s+" , " " ). trim ( );
1001+ return TextUtils . normalizeSpace ( value );
9881002 }
9891003
9901004 public static String cq (String value )
0 commit comments