Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cypress 如何从没有id或类的SelectForm中cy.get_Cypress - Fatal编程技术网

Cypress 如何从没有id或类的SelectForm中cy.get

Cypress 如何从没有id或类的SelectForm中cy.get,cypress,Cypress,如果我没有类或id,如何使用cy.get(?)。选择('2') 月 1. 2. 3. 您可以根据名称尝试以下操作,然后通过索引eq(2)查找选项以获得第二个选项。这里,eq(0)是月,eq(1)是1,eq(2)是2,依此类推 cy.get('select[name="register[personal][birthday][month]"] > option') .eq(2) .click() 您可以根据值尝试另一个: cy.get('select[name=

如果我没有类或id,如何使用
cy.get(?)。选择('2')


月
1.
2.
3.

您可以根据名称尝试以下操作,然后通过索引
eq(2)
查找选项以获得第二个选项。这里,
eq(0)是月,
eq(1)是1,
eq(2)是2,依此类推

cy.get('select[name="register[personal][birthday][month]"] > option')
      .eq(2) 
      .click()
您可以根据值尝试另一个:

cy.get('select[name="register[personal][birthday][month]').then(function($select){
   $select.val('2');
 })

第二个非常好用!这应该添加到官方的cypress文档中:)谢谢在第一个选项中,尝试从get()方法中删除“>option”,然后再试一次