Why file deletion from ul list elements takes long time period?

Good day, community.

I have approached problem making file deletion automated test. I have to work with Admin Tools page, which has list of uploaded files, which can be deleted by clicking on “X” button. After clicking button, element deletes from the list and second element in the list takes his place. From the HTML code side, it is unordered list with li elements.

My main task is after bigger test finishes, I will deploy deletion part, which will delete all files, what were uploaded before, but I have encountered problem with deleting more than one file. Using Xpath selector, I click on the button and after that I supposedly need to click on the same button, because second button place will be moved to position [1] of unordered list. But I can’t do this. After deletion there is a gap in time, when Katalon will not find same element with correct Xpath selector. So any command like WaitElementToBeVisible, Present or even Clickable won’t find element because in some moment it does not exist! I have tried to avoid it using a Delay, but it is temporary solution and won’t work if internet will slows down for a bit or something similar. Instead of this I have wrote custom keyword, which get -li elements size() and checks initial size comparing to size after deletion in cycle. After li size decreases by 1, deletion button will be clicked again. To check how long Katalon is checking deletion result, I have printing them in moment of function work. Sometimes it happens after one cycle, but another times it takes 6-7 second to delete element!

I have checked element count with same approach via javascript code in console and deletion process happens in no time, li elements deletes immediately. What I do wrong and how make X button clicks faster?

All details

Keyword code:
public class DeleteFileCycle {

@Keyword
static void deleteUploadedFilesInCycle(int maxWaitTime, float interval) {
	for (int i = 0; i < GlobalVariable.UploadFile_count; i++) {
		// Get the initial count of <li> elements
		WebDriver driver = DriverFactory.getWebDriver()
		WebElement ulElement = driver.findElement(By.xpath("//ul[@id='uploadedFilesList']"))
		List<WebElement> liElements = ulElement.findElements(By.className("list-group-item"))
		def initialLiCount = liElements.size()

		// Click delete button (position 1) for the current file
		WebUI.click(findTestObject('ORION-Admin tools/Button_X', [('position') : 1]))
		println('successfull deletion')

		// Wait for the <ul> length to change
		def startTime = System.currentTimeMillis()
		while (System.currentTimeMillis() - startTime < maxWaitTime * 1000) {
			WebElement updatedUlElement = driver.findElement(By.xpath("//ul[@id='uploadedFilesList']"))
			List<WebElement> updatedLiElements = updatedUlElement.findElements(By.className("list-group-item"))
			def currentLiCount = updatedLiElements.size()
			if (currentLiCount < initialLiCount) {
				break
			}
			WebUI.delay(interval)
			println('Delay Again')
		}
	}
	GlobalVariable.UploadFile_count = 0
}

Xpath selector to the button:
//child::li[${position}]//button[contains(@class, ‘js-remove-uploaded-file-button’)]

HTML code with UL list:

<ul id="uploadedFilesList" class="list-group list-group-flush">
    <li class="list-group-item">
        <div class="text-nowrap js-invalid-address d-flex align-items-center">
            <div class="text-truncate">LV8392I1.153</div> <button type="button"
                class="btn btn-sm btn-light js-remove-uploaded-file-button ms-auto" data-file-id="1713"
                data-toggle="tooltip" data-placement="top" aria-label="Remove"><i
                    class="fa-solid fa-xmark"></i></button>
        </div>
    </li>
    <li class="list-group-item">
        <div class="text-nowrap js-invalid-address d-flex align-items-center">
            <div class="text-truncate">LV8392I1.153</div> <button type="button"
                class="btn btn-sm btn-light js-remove-uploaded-file-button ms-auto" data-file-id="1712"
                data-toggle="tooltip" data-placement="top" aria-label="Remove"><i
                    class="fa-solid fa-xmark"></i></button>
        </div>
    </li>
</ul>
2 Likes

Hi,

I will ask my teammate and investigate it if any solution helps.

Hi!

Have you got any updates on this issue? Maybe I can provide more info or try to catch/debug this issue somehow?

You can see this phenomenon on the machine in your hand. But I can not see it on the machine in my hand. I can not think about any software problem without looking at the problem reproduced on my machine. I think it is only you who can debug your case.