@@ -76,6 +76,46 @@ export class UIElement {
76
76
return await ( await this . element ( ) ) . text ( ) ;
77
77
}
78
78
79
+ /**
80
+ * Returns if an element is selected
81
+ */
82
+ public async select ( retries : number = 3 ) {
83
+ ( await ( await this . element ( ) ) ) . click ( ) ;
84
+ let el = ( await this . element ( ) ) ;
85
+ if ( ! el ) return el ;
86
+
87
+ const hasSelectedAttr = await ( await this . element ( ) ) . getAttribute ( "selected" ) ;
88
+ if ( hasSelectedAttr ) {
89
+ let isSelected = await el . isSelected ( ) ;
90
+ while ( retries >= 0 && ! isSelected ) {
91
+ ( await ( await this . element ( ) ) ) . click ( ) ;
92
+ isSelected = await el . isSelected ( ) ;
93
+ retries -- ;
94
+ await this . _driver . sleep ( 200 ) ;
95
+ }
96
+ } else {
97
+ console . log ( `This element doesn't contains selected attribute!` ) ;
98
+ }
99
+
100
+ return el ;
101
+ }
102
+
103
+ /**
104
+ * Returns if an element is selected
105
+ */
106
+ public async isSelected ( ) {
107
+ const el = ( await this . element ( ) ) ;
108
+ if ( ! el ) return false ;
109
+
110
+ const hasSelectedAttr = await ( await this . element ( ) ) . getAttribute ( "selected" ) ;
111
+ if ( ! hasSelectedAttr ) {
112
+ console . log ( `This element doesn't contains selected attribute! Skip check!` ) ;
113
+ return true ;
114
+ } else {
115
+ return await ( await this . element ( ) ) . isSelected ( ) ;
116
+ }
117
+ }
118
+
79
119
/**
80
120
* Get web driver element
81
121
*/
@@ -318,28 +358,28 @@ export class UIElement {
318
358
/**
319
359
* Easy to use in order to chain and search for nested elements
320
360
*/
321
- public driver ( ) {
361
+ public driver ( ) : any {
322
362
return this . _element . browser ;
323
363
}
324
364
325
- /**
326
- * Swipe element left/right
327
- * @param direction
328
- */
329
- public async swipe ( direction : Direction ) {
365
+ /**
366
+ * Swipe element left/right
367
+ * @param direction
368
+ */
369
+ public async swipe ( direction : Direction ) {
330
370
const rectangle = await this . getRectangle ( ) ;
331
371
const centerX = rectangle . x + rectangle . width / 2 ;
332
372
const centerY = rectangle . y + rectangle . height / 2 ;
333
373
let swipeX ;
334
- if ( direction == Direction . right ) {
374
+ if ( direction == Direction . right ) {
335
375
const windowSize = await this . _driver . getWindowSize ( ) ;
336
376
swipeX = windowSize . width - 10 ;
337
- } else if ( direction == Direction . left ) {
377
+ } else if ( direction == Direction . left ) {
338
378
swipeX = 10 ;
339
379
} else {
340
380
console . log ( "Provided direction must be left or right !" ) ;
341
381
}
342
-
382
+
343
383
if ( this . _args . isAndroid ) {
344
384
const action = new this . _wd . TouchAction ( this . _driver ) ;
345
385
action . press ( { x : centerX , y : centerY } )
0 commit comments