I'm new to java and selenium, so forgive me if I missing something very obvious. So i have the following code where I'm trying to click a dropdown button and then click another button inside it.
public class DropDown {
private static final String URL = "https://www.browserstack.com/guide/handling-dropdown-in-selenium-without-select-class";
private static final String BUTTON = "//*[@class='bstack-mm-nav']/div[2]/button";
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get(URL);
WebElement developerButton = driver.findElement(By.xpath(BUTTON));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(10000));
wait.until(ExpectedConditions.elementToBeClickable(developerButton)).click();
WebElement buttonToClick = driver.findElement(By.xpath("//a[@title='Support']"));
buttonToClick.click();
}
}
I'm using an explicit wait to wait until the developerButton button becomes clickable. When I run this code multiple times, sometimes it runs without exceptions, and other times it throws either a TimeoutException or ElementNotInteractableException.
Now my understanding is that, with the explicit wait, it should wait either till my button becomes clickable, or till the time period I have set with the wait method has been crossed, in which case it will throw a TimeoutException. But sometimes I'm also getting the ElementNotInteractableException, which in my understanding I should not be getting because the click() action on the developerButton should only be done after it becomes clickable. Can you please shed some light on this for me.
Now while writing this question, I tried running that a bunch of times, and now I'm only getting a TimeOutException. Generally what I want to understand is the cause of this inconsistency. Thank you.