I want to select the option from the drop-down menu. I tried a number of ways but I failed.
I tried:
WebDriverWait wait = new WebDriverWait (driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("iMacs")));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("iMacs")));
waitForElementToBeDisplayed(driver.findElement(By.linkText("iMacs")), 200);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='iMacs']")));
This is my code:
WebElement element = driver.findElement(By.linkText("Product Category"));
Actions action = new Actions(driver);
action.moveToElement(element).perform();
WebDriverWait wait = new WebDriverWait (driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("iMacs")));
WebElement subElement = driver.findElement(By.linkText("iMacs"));
action.moveToElement(subElement);
action.click();
action.perform();
This is my error:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.linkText: iMacs (tried for 5 second(s) with 500 MILLISECONDS interval)
So you are hovering over some element and then trying to click on specific link? Which driver are you using? Do you actually see that this menu is correctly rendered after hover?
Your code fails on
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("iMacs")));Try with
wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("iMacs")));instead and see if it fails then (and what exception it throws in that case).And why are you using Actions API to perform click?