簡體   English   中英

如何從畫布中刪除上傳的圖像(如果有)?

[英]How to remove uploaded image(if any) from canvas?

在我的代碼中,如果有圖像被成功刪除,但是當畫布中有多個圖像時,我怎么知道我必須調用 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()
        }

    })

這就是我的處理方式,

假設有與單元格一樣多的圖像

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;  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM