Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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:Traverse文档&;在子元素中执行选择操作_Cypress - Fatal编程技术网

Cypress:Traverse文档&;在子元素中执行选择操作

Cypress:Traverse文档&;在子元素中执行选择操作,cypress,Cypress,目标:在Cypress中,遍历的树,用找到子,然后命令。选择 简而言之,我的页面文档安排如下: <div.Root> ... <div.Actions> <div.Action> ... <div.Box> ... <select.Do> <div.Action> ...

目标:在Cypress中,遍历
的树,用
找到子
,然后命令
。选择

简而言之,我的页面文档安排如下:

<div.Root>
  ...
    <div.Actions>
      <div.Action>
        ...
          <div.Box>
            ...
              <select.Do>
      <div.Action>
        ...
          <div.Box>
            ...
              <select.Do>
例如Cypress.io code,我已经找到了
的子
HTMLelement
,但仍然停留在那里,没有发现如何进一步遍历并执行命令
。选择

cy.get('div.Root').then($divRoot => {
  expect($divRoot.find('div.Actions').length).eq(1);
  cy.get('div.Actions').then( $divActions => {
    expect($divActions.find('div.Action').length).gte(1);

    // Here is where I get lost at to what to do
    // Within each <div.Action>, I want to perform select
    $divActions.find('div.Action').each(($index, $divAction) => {
       // $divAction is not a Cypress element 
       // that can perform commands like get, find, select
    })
cy.get('div.Root')。然后($divRoot=>{
expect($divRoot.find('div.Actions').length).eq(1);
cy.get('div.Actions')。然后($divActions=>{
expect($divActions.find('div.Action').length).gte(1);
//这就是我迷茫于该做什么的地方
//在每一个选项中,我要执行select
$divActions.find('div.Action')。每个($index,$divAction)=>{
//$divAction不是Cypress元素
//可以执行诸如get、find、select之类的命令
})
非常感谢您的帮助

根据每个回调中的Cypress文档,首先传递元素,然后传递索引

其次,您必须包装随cy.wrap传入的dom元素,以便能够对该元素执行cypress操作

我是如何做到这一点的:

cy.get("div.actions")
  .find("select")
  .each(($el) => {
    cy.wrap($el).select();
  });

根据每个回调中的Cypress文档,首先传递元素,然后传递索引

其次,您必须包装随cy.wrap传入的dom元素,以便能够对该元素执行cypress操作

我是如何做到这一点的:

cy.get("div.actions")
  .find("select")
  .each(($el) => {
    cy.wrap($el).select();
  });

谢谢,我会查出来的。我认为
.get(“select”)
应该是
。find(“select”)
,而
。children()
是不必要的。请参阅-cy.get()需要与cy链接。编辑答案。谢谢。我会查出来的。我认为
.get(“select”)
应该是
。find(“select”)
,和
.children()
是不必要的。请参阅-cy.get()需要被链接到cy之外。编辑答案。谢谢。