I've an AJAX based application and I want to click on element. In order to click on it, I use explicit wait for element to be clickable then click it like -
| WebElement element = new WebDriverWait(driver, 30) |
| .ignoring(NoSuchElementException.class) |
| .until(ExpectedConditions.elementToBeClickable(By.id("ribbon-connection-accessibleconnections"))); |
| |
| JavascriptExecutor js = (JavascriptExecutor) driver; |
| System.out.println("Width is " + js.executeScript("return arguments[0].offsetWidth;",new Object[] {element}).toString()); |
| System.out.println("Height is " + js.executeScript("return arguments[0].offsetHeight;",new Object[] {element}).toString()); |
| System.out.println("Document ready? " + js.executeScript("return document.readyState === \"complete\"")); |
| System.out.println("jQuery done? " + js.executeScript("return jQuery.active === 0")); |
| System.out.println("jQuery active count " + js.executeScript("return jQuery.active")); |
|
|
| element.click(); |
After wait for an element to be clickable, I can see that height width of element is positive value also document ready state is complete and no jQuery request active.(In above code, I just printed it but I wait for them to satisfy). Even though result of all above seems good but I can see on UI page still not loaded completely because after that I can see that some of the components on page are still loading. After this all, I click on an element.
But sometimes, I can see that following behaviour
1. after click whatever component is expected to appear on UI, does not appear(Note element.click() does not result into any error this indicate click has succeeded)
2. instead of click, UI appears like mouse hover was performed over the element(I can see tooltip of that element and no UI appear which was expected after click)
Could you please suggest how this can be handled? Actually this causing my tests to fail intermittently and fails at any stage randomly. Adding sleep does not cause these issues but that is not right approach.
I've been struggling a lot for stabilizing this but no luck. Your help is highly appreciated.