I created test for clicking all menu items and subitems on the page. It fails on clicking second item's subitem:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <a class="side-bar-third__link" href="/radiology/kt/golova/">...</a>
is not clickable at point (456, 824). Other element would receive the click: <div class="monitoring_link">...</div>
@Test
public void clickAllMenuItemsTest() {
System.setProperty("webdriver.chrome.driver", "libs/chromedriver/chromedriver.exe");
List<String> links = new ArrayList<>();
driver = new ChromeDriver();
driver.get("https://www.invitro.ru/radiology/");
JavascriptExecutor jsExecutor = driver;
WebDriverWait wait = new WebDriverWait(driver, 10);
final By locator = By.cssSelector("a.side-bar-second__link");
final By locatorActiveItem = By.cssSelector(".side-bar-second__items.side-bar__items--active");
final By locatorSubItems = By.cssSelector(" a.side-bar-third__link");
wait.until(ExpectedConditions.elementToBeClickable(locator));
int numberOfElementsFound = getNumberOfElementsFound(locator);
for (int pos = 0; pos < numberOfElementsFound; pos++) {
wait.until(ExpectedConditions.elementToBeClickable(locator));
final WebElement elementClickable = getElementWithIndex(locator, pos);
jsExecutor.executeScript("arguments[0].scrollIntoView(true);", elementClickable);
elementClickable.click();
wait.until(ExpectedConditions.elementToBeClickable(locatorActiveItem));
int numberOfSubElementsFound = getNumberOfElementsFound(locatorActiveItem, locatorSubItems);
for (int subPos = 0; subPos < numberOfSubElementsFound; subPos++) {
wait.until(ExpectedConditions.elementToBeClickable(locatorSubItems));
final WebElement subElementClickable = driver.findElement(locatorActiveItem).findElements(locatorSubItems).get(subPos);
jsExecutor.executeScript("arguments[0].scrollIntoView(true);", subElementClickable);
//fails here:
subElementClickable.click();
}
}
driver.quit();
}
private WebElement getElementWithIndex(By locatorActiveItem, By locatorSubItems, int index) {
return driver.findElement(locatorActiveItem).findElements(locatorSubItems).get(index);
}
private int getNumberOfElementsFound(By locatorActiveItem, By locatorSubItems) {
return driver.findElement(locatorActiveItem).findElements(locatorSubItems).size();
}
public int getNumberOfElementsFound(By by) {
return driver.findElements(by).size();
}
public WebElement getElementWithIndex(By by, int index) {
return driver.findElements(by).get(index);
}
What is could be wrong?