@@ -252,6 +252,8 @@ private List getElementList() {
252252 public String asString () {
253253 try {
254254 if (!Configuration .automationType .equals (Configuration .DESKTOP_PLATFORM )) {
255+ if (elementUI != null )
256+ return elementUI [index ].toString ();
255257 return getElementList ().get (index ).toString ();
256258 } else {
257259 return $$ (SelenideElement ).get (index ).toString ();
@@ -293,6 +295,8 @@ public UIElement first() {
293295 public int size () {
294296 if (!Configuration .automationType .equals (Configuration .DESKTOP_PLATFORM )) {
295297 try {
298+ if (elementUI != null )
299+ return elementUI .length ;
296300 return getElementList ().size ();
297301 } catch (Exception e ) {
298302 return 0 ;
@@ -446,17 +450,25 @@ public UIElement findByText(String text) {
446450 long t = System .currentTimeMillis ();
447451 long end = t +(Configuration .timeout * 1000 );
448452 while (System .currentTimeMillis () < end ) {
449- for (int i = 0 ; i < size (); i ++) {
450- if (containsText (getAppiumElement (), getAccessibilityId (), i , text )) {
451- return new Element (
452- element ,
453- SelenideElement ,
454- iOSElement ,
455- i ,
456- true ,
457- accesibilityId ,
458- accesibilityIdiOS
459- );
453+ if (elementUI != null ) {
454+ for (UIElement uiElement : elementUI ) {
455+ if (uiElement .isVisible () && uiElement .getText ().contains (text )) {
456+ return uiElement ;
457+ }
458+ }
459+ } else {
460+ for (int i = 0 ; i < size (); i ++) {
461+ if (containsText (getAppiumElement (), getAccessibilityId (), i , text )) {
462+ return new Element (
463+ element ,
464+ SelenideElement ,
465+ iOSElement ,
466+ i ,
467+ true ,
468+ accesibilityId ,
469+ accesibilityIdiOS
470+ );
471+ }
460472 }
461473 }
462474 }
@@ -494,18 +506,26 @@ public UIElement findByValue(String value) {
494506 long t = System .currentTimeMillis ();
495507 long end = t +(Configuration .timeout * 1000 );
496508 while (System .currentTimeMillis () < end ) {
497- for (int i = 0 ; i < size (); i ++) {
498- if (containsAttribute (getAppiumElement (), getAccessibilityId (), i ,
499- "value" , value )) {
500- return new Element (
501- element ,
502- SelenideElement ,
503- iOSElement ,
504- i ,
505- true ,
506- accesibilityId ,
507- accesibilityIdiOS
508- );
509+ if (elementUI != null ) {
510+ for (UIElement uiElement : elementUI ) {
511+ if (uiElement .isVisible () && uiElement .getValue ().contains (value )) {
512+ return uiElement ;
513+ }
514+ }
515+ } else {
516+ for (int i = 0 ; i < size (); i ++) {
517+ if (containsAttribute (getAppiumElement (), getAccessibilityId (), i ,
518+ "value" , value )) {
519+ return new Element (
520+ element ,
521+ SelenideElement ,
522+ iOSElement ,
523+ i ,
524+ true ,
525+ accesibilityId ,
526+ accesibilityIdiOS
527+ );
528+ }
509529 }
510530 }
511531 }
@@ -543,17 +563,25 @@ public UIElement findByEnabled() {
543563 long t = System .currentTimeMillis ();
544564 long end = t +(Configuration .timeout * 1000 );
545565 while (System .currentTimeMillis () < end ) {
546- for (int i = 0 ; i < size (); i ++) {
547- if (enable (getAppiumElement (), getAccessibilityId (), i )) {
548- return new Element (
549- element ,
550- SelenideElement ,
551- iOSElement ,
552- i ,
553- true ,
554- accesibilityId ,
555- accesibilityIdiOS
556- );
566+ if (elementUI != null ) {
567+ for (UIElement uiElement : elementUI ) {
568+ if (uiElement .isEnabled ()) {
569+ return uiElement ;
570+ }
571+ }
572+ } else {
573+ for (int i = 0 ; i < size (); i ++) {
574+ if (enable (getAppiumElement (), getAccessibilityId (), i )) {
575+ return new Element (
576+ element ,
577+ SelenideElement ,
578+ iOSElement ,
579+ i ,
580+ true ,
581+ accesibilityId ,
582+ accesibilityIdiOS
583+ );
584+ }
557585 }
558586 }
559587 }
0 commit comments