Hi! New user here. I'm very excited about KM and I can't believe I've used Macs for decades without trying it out.
I have a webpage, with the following <div> that I need to click on:
<div class="fold-bar"><label>View More</label></div>
This javascript works every time in the Javascript console in Chrome:
var elements = document.querySelectorAll('.fold-bar');
var targetElement = null;
// Loop through all elements with the class "fold-bar"
elements.forEach(function(element) {
// Check if the element has only the "fold-bar" class
if (element.classList.length === 1 && element.classList.contains('fold-bar')) {
// If it has only the "fold-bar" class, set it as the target element
targetElement = element;
}
});
// If a target element with only the "fold-bar" class was found, click it
if (targetElement) {
targetElement.click();
} else {
console.error('Target element with only "fold-bar" class not found.');
}
(I have to do a loop because a few <div>s use the fold-bar class, but this is the only one that ONLY uses class "fold-bar")
But when I run it in an "Execute JavaScript in Google Chrome" action in KM, I get an error every time:
"Target element with only "fold-bar" class not found."
I have determined that the javascript in the console obtains a list of the relevant elements (document.querySelectorAll('.fold-bar'), but the action in KM does not - var elements is empty when KM runs the javascript.
I'm at a loss for why KM would seem to be sending the correct JavaScript to the browser but it doesn't work. If I do the same thing manually it does work.
Any suggestions! TIA!