Sources: Selenium WebDriver, Chrome 73V, ChromeDriver, Java , testNG, CRM application , Eclipse
I am working on web application which is kind of CRM, loaded with tons of UI elements. One test case works today and fail tomorrow. FYI, I used fluent wait for my test cases.
I checked all the xpaths and they are good. On top of this I executed with Debug mode and tests are passing on debug mode. They are randomly flaky and un-stable , I am not sure what to do to make them stable? I don't want to use thread.sleep , off course.
Below code (just for the idea) I used to click few elements of the page , sometime Action class works sometime doesn't and sometime Click function works sometime doesn't, not sure how to handle such weird scenario?
driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);
OR
driver.findElement(By.name("submit")).sendKeys(Keys.RETURN);
OR
driver.findElement(By.name("submit")).click();
OR
WebElement webElement = driver.findElement(By.id("Your ID Here"));
Actions builder = new Actions(driver);
builder.moveToElement(webElement).click(webElement);
builder.perform();
OR
WebElement webElement = driver.findElement(By.id("Your ID here"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", webElement);
Thanks for your comments, Please see below, this is my fluent wait:
  public static boolean waitForElementToBeVisibleOrClickable (WebDriver driver, WebElement element) {
    boolean webElement = false;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
        wait = new WebDriverWait(driver, 30)
                .ignoring(NoSuchElementException.class, 
        StaleElementReferenceException.class)
                .pollingEvery(200);
        wait.until(ExpectedConditions.visibilityOf(element));
        **OR** 
        wait.until(ExpectedConditions.elementToBeClickable(element));
        Log.info("Element is visible");
        webElement = true;
    } catch (Exception e) {
        Log.error("Element is not visible");
        webElement = false;
    } finally {
        driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
    }
    return webElement;
}
 
     
    