无法使用茉莉花(量角器)定位元素

问题描述 投票:0回答:1

登录页面是一个非角度页面,当用户登录时,他/他将被重定向到主页。主页使用角度。

用于登录,我用过

        browser.ignoreSynchronization = true;
        var loginTxt = browser.driver.findElement(by.id("userNameInput"));
        var pwdTxt = browser.driver.findElement(by.id("passwordInput"));
        var signInBtn = browser.driver.findElement(by.id("submitButton"));
        loginTxt.sendKeys("test1");
        pwdTxt.sendKeys("password!");
        signInBtn.click();

用户已成功登录,我使用以下代码与主页中的元素进行交互。

        browser.ignoreSynchronization = false;
        var el = element(by.className("btn item-desktop-only inactive-btn"))
        el.click();

错误代码:信息:失败:等待量角器与页面同步时出错:“ angularJS可测试性和角度可测试性均未定义。这可能是因为这是非角度页面,或者因为您的测试涉及客户端导航,这可能会干扰量角器的引导。有关详细信息,请参见http://git.io/v4gXM

删除时

browser.ignoreSynchronization = false;

然后我得到一个错误:

Message:
    Failed: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)
  Stack:
    NoSuchElementError: No element found using locator: By(css selector, .btn.item-desktop-only.inactive-btn)

HTML IS:

<button _ngcontent-vsd-c3="" class="btn item-desktop-only inactive-btn" type="button" ng-reflect-klass="btn item-desktop-only" ng-reflect-ng-class="[object Object]"><img _ngcontent-vsd-c3="" class="orders-icon" src="/assets/icons/orders-inactive.png" srcset="/assets/icons/[email protected] 2x,/assets/icons/[email protected] 3x"> Orders </button>
jasmine protractor qa browser-automation
1个回答
0
投票

从错误中很明显,主页不是Angular App>版本2。

继续进行

browser.ignoreSynchronization = true;

您可以检查定位器是否正确。请通过在开发工具中找到来验证定位器。

人员体验:角度版应用<2在browser.ignoreSynchronization = true;下可以正常工作>

尝试等待定位器存在。

您可以在量角器中使用ExpectedConditions。

const EC = require('protractor').ExpectedConditions;
let elm = element(by.id('your id'));  
browser.wait(EC.presenceOf(e), 10000); //2nd parameter is the max timeout
expect(e.isPresent()).toBeTruthy();
© www.soinside.com 2019 - 2024. All rights reserved.