页面加载后找不到嵌套元素

时间:2018-11-27 18:39:39

标签: angular protractor

在测试规格中,我需要单击“主页”上的按钮,然后等待页面完全加载。该按钮仅被单击一次,当我重新运行规范时,它由于量角器无法到达element(by.tagName('app-banner')上嵌套元素的末端而失败

it('should click a button',  async () => {
    const EC = protractor.ExpectedConditions;
    page.login().then(() => {
      browser.wait(element(by.id('Body')).element(by.tagName('app-root')).isDisplayed, 5000).
      then(async () => {
        browser.wait(await element(by.tagName('app-root')).element(by.tagName('app-banner')).isDisplayed, 5000).
        then(async () => {
         await element(by.tagName('app-root')).element(by.tagName('app-banner')).
          element(by.id('topbar')).element(by.id('user-display')).click();
          });
        });
      });
  });

-HTML层次结构

<app-home>
   <div _ngcontent-c1 class=”layout-wrapper”>
     <app-banner>
       <div _ngcontent-c3 id=”topbar”>
          <a id=”user-display”>
             <bar-switchuser>
                <span>
                    <p-dropdown>
                    </p-dropdown>
                </span>
             </bar-switchuser>
           </a>
        </div>
    <app-banner>
</div>

1 个答案:

答案 0 :(得分:0)

您已经定义了ExpectedConditions,但没有使用它。为什么?改用isDisplayed

await browser.wait(ExpectedConditions.visibilityOf(element(by.id('Body')).element(by.tagName('app-root')), 5000, "Element is not visible in 5 sec")

相关问题