我正在尝试对一个文本字段执行sendKeys(),这可以通过Thread.sleep()来完成(我不想这样做)。现在我已经使用了5- 10秒的隐式等待,但是执行显然没有等待这个时间量。添加带有elementToBeClickable()预期条件的显式等待会导致类似的间歇性失败。
发布于 2020-12-20 20:38:01
如果您能够在调用Thread.sleep()
之后调用文本字段的sendKeys()
,这本质上意味着真正的问题出在implicit wait和/或WebDriverWait的实现上
深度潜水
同时与基于JavaScript、ReactJS、jQuery、AJAX、Vue.js、Ember.js、GWT等的应用程序的元素交互。implicit wait isn't that effective。
在这种情况下,您可以选择完全使用WebDriverWait的remove implicit wait,因为Waits的文档中明确提到:
警告:不要混用隐式和显式等待。这样做会导致不可预知的等待时间。例如,将隐式等待设置为10秒,将显式等待设置为15秒,可能会导致在20秒后发生超时。
解决方案
首先,您需要将隐式等待重新配置为0
,如下所示:
driver.implicitly_wait(0)
TimeUnit.SECONDS); (0,driver.manage().timeouts().implicitlyWait
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
相反,为elementToBeClickable()
引入WebDriverWait,如下所示:
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,“elementID”)).send_keys(“Debajyoti Sikdar")
20).until(ExpectedConditions.elementToBeClickable(By.id("elementID"))).sendKeys("Debajyoti WebDriverWait(驱动程序, Sikdar");
TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.entry#ng-touchedid='limit'"))).SendKeys("Debajyoti WebDriverWait(驱动程序, Sikdar");
参考文献
您可以在以下位置找到详细的讨论:
发布于 2021-01-19 13:09:32
在定义显式等待的同时,请确保您正在添加正确的预期等待条件。
你可以检查这个"https://itnext.io/how-to-using-implicit-and-explicit-waits-in-selenium-d1ba53de5e15".
https://stackoverflow.com/questions/65293690
复制相似问题