【问题标题】:Cannot Locate Element using Jasmine (Protractor)无法使用 Jasmine(量角器)定位元素
【发布时间】:2020-07-05 12:40:40
【问题描述】:

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

用于登录,我用过

        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();

错误代码: 信息: 失败:等待 Protractor 与页面同步时出错:“angularJS 可测试性和 Angular 可测试性都未定义。这可能是因为这是一个非 Angular 页面,也可能是因为您的测试涉及客户端导航,这可能会干扰 Protractor 的引导。有关详细信息,请参阅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 是:

<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/orders-inactive@2x.png 2x,/assets/icons/orders-inactive@3x.png 3x"> Orders </button>

【问题讨论】:

    标签: jasmine protractor qa browser-automation


    【解决方案1】:

    从错误中可以明显看出主页不是 Angular 应用 > 版本 2。

    继续

    browser.ignoreSynchronization = true;
    

    你能检查定位器是否正确。请通过在开发工具中查找来验证定位器。

    人员体验:角度应用版本 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();
    

    【讨论】:

    • 我删除 browser.ignoreSynchronization = false;和用户 broswer.sleep(5000);它现在正在工作。
    猜你喜欢
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 2016-08-06
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多