I am making a test script, during which all menu items must be clicked. If items have nested submenus, they also must be clicked.
I understand that I need to do something through the “if”. If there is a submenu, then run a function that will go through them, if there are none, then repeat the current one, but I don’t know java very well and don’t understand how to implement it. Now my functions are simply driven in a circle through one menu item and its submenus. Thanks for the help!

Code:

List<WebElement> elementList = driver.findElements(By.cssSelector("#box-apps-menu li a"));
for (int i = 0; i < numberOfMenuElements; i++) {
elementList.get(i).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("h1")));