protractor - 如何在量角器中使用 formcontrolname 从下拉列表中选择值?
问题描述
<select _ngcontent-c1="" class="form-control ng-untouched ng-pristine ng-invalid" formcontrolname="Designation" required=""><option _ngcontent-c1="" value="">Select Designation</option><!----><option _ngcontent-c1="" value="CEO">CEO</option><option _ngcontent-c1="" value="GM">GM</option><option _ngcontent-c1="" value="BodyGuard">BodyGuard</option><option _ngcontent-c1="" value="Executive">Executive</option></select>
对于上面的 html,我正在尝试使用量角器从下拉列表中选择值。尝试以下但不工作。
var EmpDesignation = element(by.cssContainingText('body.modal-open:nth-child(2) modal-container.modal.fade.show:nth-child(7) div.modal-dialog div.modal-content form.form-horizontal.ng-pristine.ng-invalid.ng-touched div.modal-body div.form-row:nth-child(2) div.col-md-10 > select.form-control.ng-pristine.ng-invalid.ng-touched:nth-child(3)', 'CEO'));
EmpDesignation.click();
错误:失败:使用定位器找不到元素:by.cssContainingText("body.modal-open:nth-child(2) modal-container.modal.fade.show:nth-child(7) div.modal-dialog div.模态内容 form.form-horizontal.ng-pristine.ng-invalid.ng-touched div.modal-body div.form-row:nth-child(2) div.col-md-10 > select.form-control .ng-pristine.ng-invalid.ng-touched:nth-child(3)", "CEO")
有多个类名称为“form-control ng-untouched ng-pristine ng-invalid”。
任何人都可以提出解决办法吗?我们可以使用 formcontrolname 标签吗?
解决方案
我会这样尝试
let EmpDesignation = element(by.xpath('//select[@formcontrol="Designation"]'));
EmpDesignation.sendKeys('CEO'); //Option 1
EmpDesignation.element(by.cssContainingText('option','CEO')) //Option 2
然而,这确实假设它formcontrol="Designation"
是独一无二的。如果该假设不正确,请告诉我,我会更新。
推荐阅读
- matlab - 符号函数的索引
- javascript - 如何在数组循环中强制执行承诺
- php - 如何使用 id 更新正确的数据?
- amazon-cloudformation - 如果已附加弹性 IP,则允许重新关联
- android - 更新 android studio 后出现的错误怎么办?
- mysql - 如何使用 MySQL 获得取决于 id 的价格
- assembly - 如何修复 Microsoft 16 位链接器上的错误 L2029?
- unit-testing - RPC 在单元测试中被阻塞
- node.js - 从 node.js 在 mysql 中创建存储过程
- python-3.x - 以最快的速度列出嵌套字典