用显式等待替换隐式等待(selenium webdriver & java) [英] Replace implicit wait with explicit wait (selenium webdriver & java)

查看:31
本文介绍了用显式等待替换隐式等待(selenium webdriver & java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用显式等待替换这种隐式等待?

How can I replace this implicit wait with an explicit one?

driver = new ChromeDriver(capabilities);

driver = new ChromeDriver(capabilities);

driver.manage().deleteAllCookies();

driver.manage().deleteAllCookies();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

这是在 Before 方法中使用的.我能够替换代码中的所有 Thread.sleep(),但我不确定对这个做了什么.

This is used in the Before Method. I was able to replace all the Thread.sleep()'s in the code, but I'm not sure what do to for this one.

推荐答案

driver 初始化后为 driver 生命周期定义一次隐式等待,并设置driver 查找敌人 WebElement 的最长时间.

Implicit wait is defined once right after the driver initialization for the driver life time, and it sets the maximum amount of time for the driver to look foe WebElement.

显式等待用于等待 WebElement 处于 cretin 条件的给定时间,并且需要在每次等待条件满足时使用.

Explicit wait is used to wait up to the given amount of time for the WebElement to be in cretin condition, and need to be used each time you are waiting for condition to met.

你不能用显式等待替换"隐式等待定义,因为它们是不同的东西,在这一点上没有条件等待.

You can't "replace" the implicit wait definition with explicit wait, as they are different thing and there is no condition to wait for in this point.

这篇关于用显式等待替换隐式等待(selenium webdriver & java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆