登录后量角器未检测到元素

Protractor does not detect element after login

在登录页面上一切正常,我可以 select 输入,select 提交按钮并单击提交按钮,url 的变化如我所料,但在由于某些原因,我不能再 select 元素了。

   // #1 login test
  it('should send check in desktop', async () => {

    await loginPage.login(environment.e2e.user.phone, environment.e2e.user.password);

    await loginPage.verifySuccessfullLogin();
    console.log('After verifySuccessfullLogin');

    await browser.sleep(3000);
    console.log('After sleep');

    const sendBtn = $('#sendCheckBtnDesktop');
    console.log(sendBtn);
    await sendBtn.click();

    // Not getting here
    await browser.sleep(10000);
  });

其余代码:

  navigateToLoginPage() {
    return browser.get(environment.e2e.baseUrl);
  }
  getPhoneInput() {
    return $('#phoneNumber');
  }
  getPasswordInput() {
    return $('#login-password');
  }
  getSubmitButton() {
    return $('#submitLoginBtn');
  }
  verifySuccessfullLogin() {
    return browser.wait(browser.ExpectedConditions.urlContains('/user/personal'), 10000);
  }

  public async login(phone: string = environment.e2e.user.phone, password: string = environment.e2e.user.password) {
    await this.navigateToLoginPage();

    const phoneInput = this.getPhoneInput();
    await phoneInput.sendKeys(phone);

    const passInput = this.getPasswordInput();
    await passInput.sendKeys(password);

    const submitBtn = this.getSubmitButton();
    await submitBtn.click();
  }

这一行有问题!

return browser.wait(browser.ExpectedConditions.urlContains('/user/personal'), 10000);

应该是

return browser.wait(protractor.ExpectedConditions.urlContains('/user/personal'), 10000);
  it('should send check in desktop', async () => {

    // *************
    // HERE!
    // *************
    await loginPage.login(environment.e2e.user.phone, environment.e2e.user.password);

    await loginPage.verifySuccessfullLogin();
    console.log('After verifySuccessfullLogin');

    await browser.sleep(3000);
    console.log('After sleep');

    const sendBtn = $('#sendCheckBtnDesktop');
    console.log(sendBtn);
    // Nothing happens
    await sendBtn.click(); <--------- you were missing await here, but you fixed it

    // Not getting here
    await browser.sleep(10000);
  });

我认为它被另一个元素隐藏了。

你可以试试:

await browser.executeScript(`
    const btn = document.getElementById('sendCheckBtnDesktop');
    btn.click();
`);

如果有效,则无法使用量角器点击此元素(可能在另一个元素后面)。

您可以阅读更多关于点击使用量角器到 JS 之间的内容。