The website is https://cloudwise.nl/ I'm trying to click on Dit is Cloudwise > Alle Cludwisers with Selenium using Java. It's a hoverable drop-down menu so I saw people handle this situation with the help of waiting until the presence of Element Located functions. so that's my code piece:
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
WebElement menu = wait.until(ExpectedConditions.presenceOfElementLocated((By.xpath("//a[@class='sf-with-ul'][contains(text(),'Dit is Cloudwise')]"))));
WebElement submenu = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]")));
action.moveToElement(menu).moveToElement(driver.findElement(By.xpath("//li[@id='menu-item-6380']//a[contains(text(),'Alle Cloudwisers')]"))).click().build().perform();
But the test still passes and it does not click. What could I be doing wrong?
To Mouse Hover on Dit is Cloudwise
and then to click on Alle Cludwisers
you need to induce WebDriverWait for the visibilityOfElementLocated() and you can use the following locator strategies:
Using xpath:
new Actions(driver).moveToElement(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[text()='Dit is Cloudwise']")))).build().perform();
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Dit is Cloudwise']//following::ul[1]/li/a"))).click();