@@ -76,6 +76,46 @@ export class UIElement {
7676 return await ( await this . element ( ) ) . text ( ) ;
7777 }
7878
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+
79119 /**
80120 * Get web driver element
81121 */
@@ -318,28 +358,28 @@ export class UIElement {
318358 /**
319359 * Easy to use in order to chain and search for nested elements
320360 */
321- public driver ( ) {
361+ public driver ( ) : any {
322362 return this . _element . browser ;
323363 }
324364
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 ) {
330370 const rectangle = await this . getRectangle ( ) ;
331371 const centerX = rectangle . x + rectangle . width / 2 ;
332372 const centerY = rectangle . y + rectangle . height / 2 ;
333373 let swipeX ;
334- if ( direction == Direction . right ) {
374+ if ( direction == Direction . right ) {
335375 const windowSize = await this . _driver . getWindowSize ( ) ;
336376 swipeX = windowSize . width - 10 ;
337- } else if ( direction == Direction . left ) {
377+ } else if ( direction == Direction . left ) {
338378 swipeX = 10 ;
339379 } else {
340380 console . log ( "Provided direction must be left or right !" ) ;
341381 }
342-
382+
343383 if ( this . _args . isAndroid ) {
344384 const action = new this . _wd . TouchAction ( this . _driver ) ;
345385 action . press ( { x : centerX , y : centerY } )
0 commit comments