如果选项名称在不同的 optgroup 下相同,如何从 select 框中 select 'option' 命名

How to select 'option' name from a select box if the option name are identical under different optgroup

如果选项名称在不同 optgroup 下相同,我们如何 select 来自 select box 的所需选项。(请参阅随附的 html 标签的屏幕截图).我尝试了以下方法,但其中 none 对我有用,任何建议都非常有用。

cy.get('option[value="Select RadioButtonList"]').select("Radio buttons (Single-select)")

// 或

cy.get('#itemType').select('Radio buttons (Single-select)').should('have.value', 'Select RadioButtonList')

// 或

 cy.get('#itemType').then(function($select){
      $select.val('Select RadioButtonList')
   })

// 或

 cy.get('select').should('have.value', 'Select RadioButtonList')

您必须将 .select() 链接到 select 对象。按值选择可能效果更好。所以试试这个:

cy .get('select#itemType') .select('Select RadioButtonList');