如何在chai量角器中选择具有特定标签的最接近元素

时间:2018-01-10 10:16:23

标签: protractor cucumber chai

如果html看起来如下:

<form>
   <div>
      <field-component>
         <div class='field'></div>
      </field-component>
   </div>
   <div>
      <div class='icon'></div>
   </div>
</form>

我可以使用fieldElement = element(by.css('.field'))获取字段,但如何才能获得与icon类最接近的元素?

1 个答案:

答案 0 :(得分:1)

试试这个:

var form = element(by.css('form'));

return form.element(by.css('.field')).isPresent().then((present) => {
    if (present) {
        return form.element(by.css('.icon')).click(); #click or whatever on this element
    }
});