首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Cypress中的下拉列表中选择未知项目

从Cypress中的下拉列表中选择未知项目
EN

Stack Overflow用户
提问于 2019-03-01 05:31:15
回答 1查看 2.5K关注 0票数 3

我只是在尝试学习这个程序,但我在从列表中选择选项时遇到了问题。问题是,我不知道这个项目的价值(我也不是真的关心,我只需要任何选择)。

下面是我当前Cypress脚本的一小段:

代码语言:javascript
复制
    it('select thing"', function() {
    cy.get('.item-summary__item-selected').click()
    cy.get('item-selector-new > .line-items > :nth-child(1) > .flex-2').select('Biggest')
    cy.get('item-selector-new > .line-items > :nth-child(2) > .flex-2').select('Big')
    cy.get('item-selector-new > .line-items > :nth-child(3) > .flex-2').select('Normal')
    cy.get('item-selector-new > .line-items > :nth-child(4) > .flex-2').?????              
})

第四个子行项目的HTML如下所示:

代码语言:javascript
复制
<div class="line-item" ng-if="$ctrl.suggested_item.length <= $ctrl.item.length"> <span class="flex-1">Item</span>
<select av-tab-item="" groupindex="1" tabindex="4" class="flex-2 form-control ng-pristine ng-untouched ng-valid ng-empty" ng-model="$ctrl.selected_item_id" ng-options="item.item_id as item.item_name for item in $ctrl.items | orderBy:'sort_order'" ng-disabled="!$ctrl.items.length" ng-change="$ctrl.handleItemSelected()" data-e2e="SELECTOR_NEW_TEST_ITEM_SELECT">
    <option value="?" selected="selected"></option>
    <option label="label name 1" value="string:186199ee-0ab6-464a-8b28-f93ee10e8bdf">label name 1</option>
    <option label="label name 2" value="string:1d58a921-e393-49f5-8df8-30243d14ec4b">label name 2</option>
    <option label="label name 3" value="string:c24d7478-4a7f-42cc-93e5-c27493f921c0">label name 3</option>
    <option label="label name 4" value="string:aa469cd5-b7fe-454b-b67b-9dd9af70038e">label name 4</option>
</select>
<br>

select()函数帮不了我,因为我不知道要选择的值,因为这些选项经常变化。我尝试过first()、last()、eq(),可能还有其他几个,但我不确定哪里出错了。任何指导都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-01 05:47:45

下面是如何使用基于索引的select()。例如,您可以获取select4th值,然后使用.then()生成value

代码语言:javascript
复制
cy.get('select.myselect option').eq(4).invoke('val').then((val)=>{
  cy.get('select.myselect').select(val)
})

// .eq(n) yields the nth element
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54934594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档