@@ -414,52 +414,38 @@ When(/^(I|we)* fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr
414414} ) ;
415415
416416/**
417- * Selecting the option in the dropdown list field by its text label.
418- *
417+ * Selecting the option in the dropdown list field by its text label
419418 * Example: When I select "Mercedes" from "Cars"
419+ * Example: When I select "saab" from "#cars"
420+ * Example: When I select "Mercedes" from "cars"
420421 *
421422 */
422- When ( / ^ ( I | w e ) * s e l e c t " ( [ ^ " ] * ) ? " f r o m " ( [ ^ " ] * ) ? " $ / , function ( pronounCase , option , dropdownlist ) {
423+ When ( / ^ ( I | w e ) * s e l e c t " ( [ ^ " ] * ) ? " f r o m " ( [ ^ " ] * ) ? " $ / , function ( pronounCase , option , selectList ) {
423424
424- const elementField = browser . element . findByText ( dropdownlist , { exact : true } ) ;
425- browser . getAttribute ( elementField , 'for' , function ( eleAttribute ) {
426- return browser . waitForElementVisible ( 'css selector' , '#' + eleAttribute . value )
427- . click ( '#' + eleAttribute . value )
428- . click ( browser . element . findByText ( option , { exact : true } ) )
429- . click ( '#' + eleAttribute . value ) ;
430- } ) ;
431- } ) ;
425+ const hasASpace = selectList . indexOf ( ' ' ) ;
432426
433- /**
434- * Selects option in select field.
435- *
436- * Example: When I select "Mercedes" from "cars" its "id" attr
437- * Example: When I select "Saab" from "#cars" by attr
438- *
439- */
440-
441- When ( / ^ ( I | w e ) * s e l e c t " ( [ ^ " ] * ) ? " f r o m " ( [ ^ " ] * ) ? " b y ( i t s ) * ( " ( [ ^ " ] * ) ? " ) * ( a t t r i b u t e | a t t r ) $ / , function ( pronounCase , option , attrValue , itsCase , attr , attrCase ) {
442-
443- const hasASpace = attrValue . indexOf ( ' ' ) ;
444-
445- var selector = '' ;
446- if ( ( attrValue . startsWith ( '#' ) || attrValue . startsWith ( '.' ) ) && hasASpace == - 1 ) {
447- selector = attrValue ;
448- }
449- else if ( ! attr && hasASpace == - 1 ) {
450- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]' ;
427+ let selector = '' ;
428+ if ( ( selectList . startsWith ( '#' ) || selectList . startsWith ( '.' ) ) ) {
429+ selector = selectList ;
451430 }
452- else if ( ! attr && hasASpace > - 1 ) {
453- selector = '[value ="' + attrValue + '"],[placeholder ="' + attrValue + '"]' ;
431+ else if ( hasASpace == - 1 ) {
432+ selector = '[name ="' + selectList + '"],[id ="' + selectList + '"],[class="' + selectList + '"]' ;
454433 }
455434 else {
456- selector = '[' + attr + '="' + attrValue + '"]' ;
435+ selector = browser . element . findByText ( selectList , { exact : true } ) ;
457436 }
458437
459- return browser . waitForElementVisible ( 'css selector' , selector )
460- . click ( selector )
461- . click ( browser . element . findByText ( option , { exact : true } ) )
462- . click ( selector ) ;
438+ let optionValue = '' ;
439+ const result = option . toLowerCase ( ) ;
440+
441+ if ( result == option ) {
442+ optionValue = '[value="' + option + '"]' ;
443+ }
444+ else {
445+ optionValue = browser . element . findByText ( option , { exact : true } ) ;
446+ }
447+
448+ return browser . click ( selector ) . click ( optionValue ) . click ( selector ) ;
463449} ) ;
464450
465451/**
0 commit comments