2017-02-22 34 views
0

当我添加一个具有某个值的新按钮时,它会动态添加到DOM中。此按钮无棱角HTML元素是:量角器中的动态属性值元素定位器

<li class="ui-state-default droppable ui-sortable-handle" id="element_98" data-value="2519"> 
    25.19 EUR 
<button type="button" class="btn btn-default removeParent"> 
<span class="glyphicon glyphicon-remove" aria-hidden="true"> 
</span> 
</button> 
</li> 

一旦我删除此按钮,我要检查它不再存在。元素我在寻找为data-value="2519",这可能是任何东西我设置,例如像2000,1000,500,1050,...

在页面目标文件我曾尝试使用以下命令:

this.newValueButtonIsNotPresent = function(item) { 
     newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.css('[data-value="' + item + '"]')); 
     return newValueButton.not.isPresent(); 
    }; 

而且在规范文件中我调用这个函数如下:

var twentyEurosButtonAttributeValue = '2000'; 

describe(".... 
    it ("... 
     expect(predefined.newValueButtonIsNotPresent(twentyEurosButtonAttributeValue)).toBeTruthy(); 

我知道这是不正确的,但我怎么能实现类似的东西或者有另一种方式?

回答

1

愚蠢的我,我找到了一个简单的解决方案。相反,动态定位的元素我所在的第一个列表中,这始终是一个,这是新增加的,然后检查,如果是文本不匹配:

页对象文件:

this.newValueButtonIsNotPresent = function() { 
     newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.tagName('li')).first(); 
     return newValueButton.getText(); 
    }; 

规格文件:

// verify element 20.00 EUR is not present 
predefined.newValueButtonIsNotPresent().then(function(value) { 
    expect(value).not.toEqual(twentyEurosText); 
}); 
相关问题