如果隐式和显式等待都在Framework中使用怎么办 [英] What if Implicit and Explicit wait, both are used in Framework

查看:106
本文介绍了如果隐式和显式等待都在Framework中使用怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解它的等待和使用.但是我不知道的一件事是:如果我将隐式等待放在顶部5秒钟,然后使用显式等待元素.那么硒将如何表现.尝试过但无法在网上获得满意的答案.

I understand both waits and use of it. But one thing that I could not figure out is : If I put implicit wait for 5 seconds at top and then use explicit wait for an element. Then how selenium will behave. Tried but could not get satisfactory answer on net.

推荐答案

首先了解显式和隐式等待的概念

First understand the concepts of Explicit and Implicit wait

隐式等待:隐式等待是告诉WebDriver在尝试查找一个或多个元素(如果它们不立即可用)时轮询DOM一定的时间.默认设置为0.设置后,将在WebDriver对象实例的生存期内设置隐式等待. 例如:

Implicit Wait: An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance. For Example:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

明确等待:

  1. 显式等待是您定义的代码,用于等待特定条件发生后再继续执行代码.
  2. 在某些情况下,显式等待在功能上等同于隐式等待,这意味着 a)在未像下面那样预定义等待时间的地方(请注意,它们在方法类别上是不同的,它们属于显式或隐式)

  1. An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code.
  2. There are some cases where the explicit wait is functionally equivalent to implicit wait, means a) Where waiting time is not predefined like below (please note they were distinct by method category they belong explicit or implicit)

WebDriverWait wait = new WebDriverWait(driver, 10);

WebElement元素= wait.until(ExpectedConditions.elementToBeClickable(By.id("someid"))));

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

b)如果网络驱动程序有时间等待10秒,但在5秒钟后找到该元素,则网络驱动程序将继续运行.

b) Cases where the webdriver has a time to wait 10 seconds but at the 5 second the element was found then the webdriver will proceed.

您的问题的答案: 1)假设您已定义10秒,然后驱动程序等待10个最大值,但至少可以等待0.001秒,这意味着在隐式等待的情况下,我们必须为等待给出最大限制,而最小限制取决于查找元素或获取条件完成.

Answer of your Question: 1) Suppose you have defined 10 seconds then driver waits for 10 maximum but at minimum it can wait for 0.001 seconds means in cases of implicit wait we have to give maximum limit for wait while minimum limit depends on the finding the element or getting the condition done.

2)在显式等待中,但在某些情况下,webdriver必须等待最大限制.

2) While in explicit wait except some case webdriver has to wait for maximum limit.

参考:

硒显式和隐式等待

这篇关于如果隐式和显式等待都在Framework中使用怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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