I'm trying to click to a react JS element programmatically.
for example please check this link: Click Here
I'm unable to click to the swatch images, which will change the main product image.
I tried with this below code:
document.querySelector('#product-selection-4476800 > section.np-sku-filters > div.np-circular-swatches.small > ul > li:nth-child(2) > a').click();
document.querySelector('#product-selection-4476800 > section.np-sku-filters > div.np-circular-swatches.small > ul > li:nth-child(2) > a > span > img').click();
Both are not working. I also tried
function clickElement(el){
var ev = document.createEvent("MouseEvent");
ev.initMouseEvent(
"click",
window, null,
false, false, false, false,
0, null
);
el.dispatchEvent(ev);
}
Still the element is not changing.
Thanks!