【问题标题】:Test automation -Problem with choosing the item from dropdown测试自动化 - 从下拉列表中选择项目的问题
【发布时间】:2020-05-15 00:58:18
【问题描述】:

我想从模式窗口的下拉列表中选择项目。 功能是

setItemFromDropDownList(urlElement: ElementFinder, n: number) {

        this.clickElement(urlElement);
        urlElement.all(by.tagName('li')).get(n - 1).click();
    }

但这给了我一个错误消息: 失败:索引超出范围。试图访问 index: 1 处的元素,但只有 0 个元素与定位器 By(css selector, li) 匹配

元素由id映射

serviceDropdown: ElementFinder=element(by.id('servicePhase'));

html中的一项

<p-dropdownitem class="ng-tns-c8-390 ng-star-inserted" style=""><li role="option" class="ui-dropdown-item ui-corner-all" aria-label="Paczka pocztowa zagraniczna"><!----><span class="ng-star-inserted">Paczka pocztowa zagraniczna</span><!----></li></p-dropdownitem>

我认为它的 cosed 因为下拉菜单在模态窗口上,所以我该怎么办?

【问题讨论】:

    标签: typescript automation jasmine protractor automated-tests


    【解决方案1】:

    测试失败的时候需要跟踪,可能是因为页面上没有显示下拉列表值导致失败,需要先等到可见再选择:

    var EC = protractor.ExpectedConditions;
    setItemFromDropDownList(urlElement: ElementFinder, n: number) {    
        this.clickElement(urlElement);     
        browser.driver.wait(function () {
        browser.wait(EC.visibilityOf(urlElement.all(by.tagName('li')).get(n - 1)), 10000);
        urlElement.all(by.tagName('li')).get(n - 1).click();
    });
    }
    

    【讨论】:

    • 谢谢。我会尝试你的解决方案,但我也找到了这样的方法: mainLib.clickElement(dropdownName); dropdownName.all(by.xpath('/html/body/div[3]/div/ul/p-dropdownitem[1]/li')).click();它有效。
    猜你喜欢
    • 1970-01-01
    • 2011-07-19
    • 2014-08-26
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多