angularjs – 使用css元素来检查量子变量中是否存在元素
发布时间:2020-12-17 08:10:55 所属栏目:安全 来源:网络整理
导读:在量角器端到端测试,我想检查元素是否存在使用元素(by.css(…)),我的代码: var myElement = element(by.css('.elementClass'));expect(myElement).toBeUndefined; 这个测试失败了,它说: Expected { locator_ : { using : 'css selector',value : 'div[n
在量角器端到端测试,我想检查元素是否存在使用元素(by.css(…)),我的代码:
var myElement = element(by.css('.elementClass')); expect(myElement).toBeUndefined; 这个测试失败了,它说: Expected { locator_ : { using : 'css selector',value : 'div[ng-switch- when="resultNav"]' },parentElementFinder_ : null,opt_actionResult_ : undefined,opt_index_ : undefined,click : Function,sendKeys : Function,getTagName : Function,getCssValue : Function,getAttribute : Function,getText : Function,getSize : Function,getLocation : Function,isEnabled : Function,isSelected : Function,submit : Function,clear : Function,isDisplayed : Function,getOuterHtml : Function,getInnerHtml : Function,toWireValue : Function } to be undefined. 之后,我试图用一个承诺: element(by.css('.elementClass')).then( functtion(data) { expect(data.getText()).toBeUndefined(); }); 这会导致错误: Error: No element found using locator By.CssSelector(...) 是的,我知道没有元素会被找到,但是如何使用element(by.css(…))创建一个工作测试? 有谁知道如何实现这一点?或者是元素(by.css())不是在这里使用的方法?
您可以测试该元素是否存在。
Here is the protractor docs为isPresent函数。
那么你的代码就像这样: var myElement = element(by.css('.elementClass')); expect(myElement.isPresent()).toBeFalsy(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |