function isColorGray(element) {
const color = window.getComputedStyle(element).backgroundColor;
const rgb = color.match(/\d+/g);
const [r, g, b] =
rgb.map (Number);
return r === g && g === b;
}
function clickIfNotGray(element) {
if (!isColorGray(element)) {
element.click ();
}
}
const elements = document.querySelectorAll('.your-element-selector');
let clicks = 0;
for (let element of elements) {
if (clicks >= 9) break;
clickIfNotGray(element);
clicks++;
}