如何使用量角器检查此页面中的所有复选框?
我试图以这种方式访问元素,但是似乎没有用。
while len(pointDict) > 1:
shape = pointDict[startOid]
pointDict.pop(startOid)
X = shape.centroid.X
Y = shape.centroid.Y
Z = shape.centroid.Z
nextOid = None
distances={}
#minSquaredDist = math.inf
for otherOid, otherShape in pointDict.items():
X2 = otherShape.centroid.X
Y2 = otherShape.centroid.Y
Z2 = otherShape.centroid.Z
squaredDist = sqrt((X-X2)**2+(Y-Y2)**2)
distances[otherOid]=squaredDist
minSearch=(min(distances.items(), key=lambda x:x[1]))
print minSearch, minSearch[0]
startOid = minSearch[0]
答案 0 :(得分:1)
您的方法无效,因为mat-card-title
没有任何子元素。链接element()
调用时,它始终仅搜索子元素。
要选择正确的元素,我们必须采用父级mat-card
并按by.cssContainingText()
进行过滤。
过滤后,我们必须找到mat-pseudo-checkbox
元素并向这些基础元素发送点击。
可以通过以下方式实现:
// select correct element group
let wrapper = element.all(by.tagName('mat-card'))
.filter(el => el.element(by.tagName('mat-card-title'))
.getText()
.then(text => {
console.log('looking if\'', text, '\'contains Classifications');
return text.indexOf('Classifications') > -1;
}));
wrapper.all(by.css('mat-card-content mat-selection-list mat-list-option .mat-list-item-content .mat-list-text'))
.each(async el => await el.click());
量角器秘籍:
量角器的通用样式指南=> https://github.com/CarmenPopoviciu/protractor-styleguide
备忘单=> https://gist.github.com/javierarques/0c4c817d6c77b0877fda
随着测试套件的增长,您应该考虑使用Page Object Model
模式进行测试。我们将其用于测试,这是分离测试逻辑的绝佳模式。 => https://www.thoughtworks.com/insights/blog/using-page-objects-overcome-protractors-shortcomings