我是新出生的质量检查人员,我在这里尝试编写一个量角器脚本,以从下拉列表中选择一个选项。我的下拉菜单中有2个选项,我正在尝试从数字中选择它。
这是我正在使用的代码。
var selectDropdownbyNum = function ( element, optionNum ) {
if (optionNum){
var options = element.findElements(by.tagName('entity.company_id as entity.company_name for entity in entities'))
.then(function(options){
options[1].click();
});
}
};
页面加载时,默认情况下会选择选项2。我需要从下拉列表中选择选项1。但是,我的代码没有做到这一点。
这是select选项的代码段。
<select required="required" class="form-control empty ng-pristine ng-valid ng-not-empty ng-valid-required ng-touched" name="entity_id" ng-model="invoice.entity_id" ng-options="entity.company_id as entity.company_name for entity in entities" ng-required="true" ng-change="entitySelect(invoice.entity_id)">
<option value="string:568f97841a4885e5de39900e" label="Option Global">Option Global</option>
<option selected="selected" value="string:568f976a1a4885e5de39900d" label="Option Computer Studies">OptionComputer Studies</option>
</select>
提前致谢 :)
找到了完美的答案。
element.all(by.css('cssSelector of the dropdown')).each(function (eachElement, index)
{
eachElement.click();// select the <select>
browser.driver.sleep(500);// wait for the renderings to take effect
element(by.css('cssSelector of option want to select')).click();// select the first md-option
browser.driver.sleep(500);// wait for the renderings to take effect
});
这就像平静:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句