2017-05-19 1 views
0

Ich versuche, die dritte Option in einer Dropdown-Liste auszuwählen. Im Folgenden sind einige Details über das Element:Fehlersuche Winkelelement für Winkelmesser UI Nav Test

Outer HTML:

<md-option _ngcontent-c6="" role="option" ng-reflect-value="last90Days" tabindex="0" id="md-option-2" aria-selected="false" aria-disabled="false" class="mat-option"><!--bindings={ 
    "ng-reflect-ng-if": "false" 
}--> Last 90 Days <!--bindings={ 
    "ng-reflect-ng-if": "true" 
}--><div class="mat-option-ripple mat-ripple" md-ripple="" ng-reflect-trigger="[object HTMLElement]"> </div> </md-option> 

CSS-Selektor:

#md-option-37 > div:nth-child(1) 

Sorry für die schreckliche Formatierung. Wenn jemand Vorschläge zur Auswahl des Dropdown-Elements "Letzte 90 Tage" hat, wäre ich sehr dankbar. Ich benutze immer die shorthand notation, für den Rest der Wähler

Antwort

2

Nach dem, was ich eine der AngularJS aus Ihrer Info verstehen md-select Sie die folgende

// Open the md-select, use the correct selector, this is a demo 
 
$('md-select').click(); 
 

 
// There is an animation, I don't know how long, you need to wait for the animation to be finished. 
 
// Quick and dirty is a browser.sleep(), but it's better to find a more stable way because if the animation will take longer in the future your test will break 
 
browser.sleep(500); 
 

 
// Click on you option, this can be done in several ways 
 

 
// By index 
 
$$('md-option').get(1).click(); 
 
// By text 
 
element(by.cssContainingText('md-option', 'your text')).click(); 
 

 
// Wait for the menu to close, this is also an animation 
 
browser.sleep(500);

Für element(by.css('selector')); tun müssen siehe die docs of Protractor.

Ich würde empfehlen, einen besseren Weg zu verwenden, um auf die Animation zu warten. Hier habe ich eine browser.sleep() verwendet, aber es ist nicht zukunftssicher. Sie möchten nicht, dass sich Ihr Skript auf den Schlaf verlässt.

Ich hoffe, es hilft.

+0

vielen dank! – rHenderson