Clicking
Clicking
// Main function: Look for the record with codeId on the current page,
// and if found, click its up button. If not found, try navigating pages.
// It repeats until it has clicked the up button the desired number of times.
function clickUpMultipleTimes(codeId, times) {
let clickCount = 0;
function checkAndClick() {
// Read the current page's records.
let tableBody = document.querySelector("#diagnosisKendoGrid tbody");
if (!tableBody) {
console.error("Table body not found!");
return;
}
let rows = tableBody.querySelectorAll("tr");
let found = false;
rows.forEach(row => {
let cells = row.querySelectorAll("td");
if (cells.length >= 5 && cells[4].innerText.trim() === codeId) {
found = true;
}
});
if (found) {
// If record is visible and we haven't yet clicked enough times, click up
once.
if (clickCount < times) {
if (clickMoveButtonByCodeId(codeId, "up")) {
clickCount++;
console.log(`Clicked up ${clickCount} time(s) for ${codeId}`);
// Wait for the move action to complete, then check again.
setTimeout(checkAndClick, 1000);
} else {
console.error(`Failed to click up for ${codeId}`);
setTimeout(checkAndClick, 1000);
}
} else {
// Finished clicking the desired number of times.
// Navigate to the first page before finishing.
let firstPageButton = document.querySelector('a[title="Go to the first
page"]');
if (firstPageButton && !firstPageButton.classList.contains("k-state-
disabled")) {
firstPageButton.click();
console.log(`Navigating to the first page...`);
setTimeout(() => {
console.log(`Finished clicking up ${times} times for ${codeId}`);
}, 2000); // Wait for first page to load
} else {
console.log(`Finished clicking up ${times} times for ${codeId}`);
}
}
} else {
// If record is not found on the current page, try navigating.
let nextButton = document.querySelector('a[title="Go to the next page"]');
if (nextButton && !nextButton.classList.contains("k-state-disabled")) {
nextButton.click();
console.log(`Record ${codeId} not found. Switching to next page.`);
setTimeout(checkAndClick, 2000);
} else {
let prevButton = document.querySelector('a[title="Go to the previous
page"]');
if (prevButton && !prevButton.classList.contains("k-state-disabled")) {
prevButton.click();
console.log(`Record ${codeId} not found. Switching to previous page.`);
setTimeout(checkAndClick, 2000);
} else {
console.warn(`Record ${codeId} not found on any navigable page.`);
}
}
}
}
checkAndClick();
}