如何从画布中删除上传的图像(如果有)?

vtwuwzda  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(319)

在我的代码中,如果存在图像,则成功删除图像,但是当画布中有多个图像时,我如何知道必须调用remove_image()函数多少次?我的条件是,如果主体发现画布为空,则上载图像,否则删除上载的图像。
这是我的密码

cy.get('body').each((body) => {
        if (body.find(':nth-child(2) > .front-upload > :nth-child(2) > .table > .table-cell').length > 0) {

            const filepath = "Front.jpg"
            imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
            cy.wait(60000)
            cy.Flip_image()
        }
        else {

            // REMOVE ELEMENT
            cy.log('Remove Image')
           // There is 5 uploaded image that's why this function call 5 times But this is not right structure.       
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()
            cy.Remove_image()

            // UPLOAD IMAGE
            cy.wait(1000)
            const filepath = "Front.jpg"
            imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
            cy.wait(60000)
            cy.Flip_image()
        }

    })
nkcskrwz

nkcskrwz1#

这就是我的方法,
假设有和细胞一样多的图像

cy.get(':nth-child(2) > .front-upload > :nth-child(2) > .table')
  .then($table => {

    const imageCount = $table.find('.table-cell').length;  

    for (let i = 0; i < imageCount; i++) {
      cy.Remove_image()
    })

    // UPLOAD IMAGE
    cy.wait(1000)
    const filepath = "Front.jpg"
    imageupload.fileuploadInput().attachFile(filepath, { subjectType: 'drag-n-drop' })
    cy.wait(60000)
    cy.Flip_image()

  })

如果某些单元格可能为空,则可以进行计数 <img> 而不是标签

const imageCount = $table.find('img').length;

相关问题