0% found this document useful (0 votes)
13 views2 pages

Clicking

The document contains a JavaScript function for navigating a table in a web application to click an 'up' button associated with a specific code ID. It checks for the presence of the code ID in the table, clicks the button if found, and navigates through pages if not. The function also includes error handling and logs actions to the console during execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Clicking

The document contains a JavaScript function for navigating a table in a web application to click an 'up' button associated with a specific code ID. It checks for the presence of the code ID in the table, clicks the button if found, and navigates through pages if not. The function also includes error handling and logs actions to the console during execution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

function Execution() {

function clickMoveButtonByCodeId(codeId, direction) {


let tableBody = document.querySelector("#diagnosisKendoGrid tbody");
if (!tableBody) {
console.error("Table body not found!");
return false;
}
let rows = tableBody.querySelectorAll("tr");
for (let row of rows) {
let cells = row.querySelectorAll("td");
if (cells.length >= 5) {
let value = cells[4].innerText.trim(); // 5th column holds the codeId
if (value === codeId) {
let btn = direction === "up"
? row.querySelector("img[name='moveUp']")
: row.querySelector("img[name='moveDown']");
if (btn) {
btn.click();
console.log(`Clicked ${direction} button for ${codeId}`);
return true;
} else {
console.error(`Button not found for ${codeId}`);
}
}
}
}
return false;
}

// 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();
}

return clickUpMultipleTimes("%CurrentItem2%", %TextAsNumber%);


}

You might also like