// Wait until the page is fully loaded window.onload = function() { // Sleep for 5 seconds setTimeout(() => { // Call the function to click the correct dropdown clickCorrectDropdown(); }, 5000); } function clickCorrectDropdown() { alert("Page loaded"); const divs = document.querySelector("div.azc-validationBelowCtrl"); if (divs) { // correct div contains in data-bind: "pcControl: groupByDropdown" const correctDiv = Array.from(divs).find(div => div.getAttribute("data-bind").contains("groupByDropdown")); correctDiv.click() correctDiv.children().forEach(child => { if (child.classList.contains("azc-formElementSubLabelContainer")) { child.children().forEach(subChild => { if (child.classList.contains("azc-formElementContainer")) { subchild.children().forEach(subSubChild => { if (subSubChild.classList.contains("fxc-dropdown-popup")) { subSubChild.children().forEach(subSubSubChild => { if (subSubSubChild.getAttribute("aria-label") === "List of options") { subSubSubChild.children().forEach(subSubSubSubChild => { if (subSubSubSubChild.classList.contains("fxc-inner-popup")) { subSubSubSubChild.children().forEach(option => { option.children().forEach(optionChild => { if (optionChild.innerHTML.contains("Group by type")) { optionChild.click(); return; } }) }); } }); } }); } }); } }); } }); } }