Javascript 量角器在允诺后找不到相同的元素

Javascript 量角器在允诺后找不到相同的元素,javascript,angular,typescript,testing,protractor,Javascript,Angular,Typescript,Testing,Protractor,我试图从量角器中的一个元素中获取文本,在对文本进行处理后,我想单击同一个元素。这就是我所拥有的 HTML: {{user?.login} 量角器试验: describe('Login OK with correct pass', () => { it('should login successfully with admin account', () => { // logging username.clear(); use

我试图从量角器中的一个元素中获取文本,在对文本进行处理后,我想单击同一个元素。这就是我所拥有的

HTML:

{{user?.login}
量角器试验:

describe('Login OK with correct pass', () => {
    it('should login successfully with admin account', () => {
        // logging

        username.clear();
        username.sendKeys('admin');
        password.clear();
        password.sendKeys('admin');
        element(by.css('button[type=submit]')).click();
        // check if the username <span> has the current login username

        const expect2 = /admin/;
        const spanuser = element(by.css('span#spanuser'));
        spanuser.getText().then((value) => {
            console.log('inside');
            console.log(value ? value : 'no value');
            expect(value).toMatch(expect2);
        });
        // then i try to click on the same span, to do some stuff

        spanuser.click().then(() =>  {
            console.log('It has been pressed!');
        });
    });
});
description('Login OK with correct pass',()=>{
它('应使用管理员帐户成功登录',()=>{
//伐木
username.clear();
username.sendKeys('admin');
password.clear();
password.sendKeys('admin');
元素(by.css('button[type=submit]'))。单击();
//检查用户名是否具有当前登录用户名
const expect2=/admin/;
const spanuser=element(by.css('span#spanuser');
spanuser.getText().then((值)=>{
console.log('inside');
log(值?值:“无值”);
expect(值).toMatch(expect2);
});
//然后我试着点击相同的跨度,做一些事情
span用户。单击()。然后(()=>{
console.log('它已被按下!');
});
});
});
第一部分工作得很好,它得到了测试并通过了预期,但是当我尝试在span上执行click()函数时,我得到了以下错误:

失败:等待异步角度任务在5秒后完成时超时。这可能是因为当前页面不是角度应用程序。有关更多详细信息,请参阅常见问题解答:

等待带有定位器的元素时-locator:By(css选择器, span#span用户)

我试过什么:

  • browser.waitForAngular()在spanuser.click()之前

  • 浏览器。等待(10000),然后单击用户。单击()

  • 在beforeAll函数中还有一个waitForAngular()

有人对此有想法吗?这对我来说真的没有任何意义,为什么找不到以前已经找到的元素呢


非常感谢

在量角器conf.js的
onPrepare
中添加
browser.waitForAngularEnabled('false')

onPrepare: function() {
   browser.waitForAngularEnabled('false')
   // if you set this in onPrepare(), it will be a global setting, will
   // effect all script, so you no need to set it in other place.
}

在配置中使用jasmin defaulttimeoutinterval,而不是手动睡眠

jasmineNodeOpts: {
   defaultTimeoutInterval: 250000
    },
     allScriptsTimeout: 180000

在spanuser之前,请尝试
browser.waitForAngularEnabled(false)
。类型为“false”的click()参数不可分配给类型为“string”的参数添加了该行,现在它甚至无法通过第一个expect。错误:失败:使用locator:By(css选择器,span#spanuser)未找到任何元素以防万一,该元素确实存在,因为它以前已被找到。修复后,我只需使用browser.sleep(10000)手动等待
jasmineNodeOpts: {
   defaultTimeoutInterval: 250000
    },
     allScriptsTimeout: 180000