I am trying to do a sendKeys() to a text field , which can be accomplished by Thread.sleep() ( which I want to avoid ) . Now I have used implicit wait of 5 - 10 seconds but the execution visibly is not waiting for that amount of time . Adding explicit wait with expected conditions of elementToBeClickable() results similar intermittent failure.
-
Provide the code you've tried. – DMart Dec 14 '20 at 17:39
2 Answers
If you are able to invoke sendKeys()
to a text field after invoking Thread.sleep()
essencially implies that the real issue is with the implementation of implicit wait and/or WebDriverWait
Deep Dive
While interacting with elements of an application based on JavaScript, ReactJS, jQuery, AJAX, Vue.js, Ember.js, GWT, etc. implicit wait isn't that effective.
Insuch cases you may opt to remove implicit wait completely with WebDriverWait as the documentation of Waits clearly mentions:
Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.
Solution
First you need to reconfigure implicit wait to 0
as follows:
Python:
driver.implicitly_wait(0)
Java:
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
DotNet:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
Instead induce WebDriverWait for the elementToBeClickable()
as follows:
Python:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "elementID"))).send_keys("Debajyoti Sikdar")
Java:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("elementID"))).sendKeys("Debajyoti Sikdar");
DotNet:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.entry#ng-touched[id='limit'][name='limit']"))).SendKeys("Debajyoti Sikdar");
References
You can find a detailed discussion in:

- 183,867
- 41
- 278
- 352
While defining explicit wait, please make sure that you are adding correct Expected Conditions.
You can check this "https://itnext.io/how-to-using-implicit-and-explicit-waits-in-selenium-d1ba53de5e15".

- 1,314
- 1
- 4
- 17