# How to control time in appium when find element

**URL:** <https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500>\
**Category:** Support\
**Created:** [August 6, 2015, 5:58am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500 "2015-08-06T05:58:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![iRANG\_QA](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@iRANG\_QA](https://discuss.appium.io/u/iRANG_QA)\
**Post date:** [August 6, 2015, 5:58am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/1 "2015-08-06T05:58:29Z")

</div>

I am using Appium and selenium web driver for Android application automation testing , Since last 3 weeks I am noticing that when I try to find elements with array , Appium find it continue at least for 2 minutes always and I want to make that time like 30 seconds.

My Code is here :

> List uploaderror = driver.findElements(By.xpath(AppConstants.uploaderror));

> if(uploaderror.size()\<=0)  
> {

> ```
> //Do Something
> 
> ```
> 
> }

In above code I am trying to find multiple elements and depends on element size I apply further action. Issue is appium takes very long time to find element , I want to control that time. I have tried all types of waits but no success.

Please let me know if anyone already faced this and resolved.

---

<div class="post-metadata">

**Author:** ![willosser](https://discuss.appium.io/user_avatar/discuss.appium.io/willosser/32/2454_2.png) [@willosser](https://discuss.appium.io/u/willosser)\
**Post date:** [August 7, 2015, 6:31pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/2 "2015-08-07T18:31:26Z")

</div>

We had a lot of problems getting the timing for searching for elements under control. We decided to use the Selenium wait object to limit the amount of time that we search. To wit,

wait = Selenium::WebDriver::Wait.new(timeout: 30, interval: 1)  
begin  
wait.until  
# findElement…  
end  
rescue Selenium::WebDriver::Error::TimeOutError

# report failure

end

---

<div class="post-metadata">

**Author:** ![Umar\_Khan](https://discuss.appium.io/user_avatar/discuss.appium.io/umar_khan/32/6847_2.png) [@Umar\_Khan](https://discuss.appium.io/u/Umar_Khan)\
**Post date:** [August 7, 2015, 7:48pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/3 "2015-08-07T19:48:55Z")

</div>

There are implicit and explicit waits. Explicit waits allow you to define maximum wait time and as the condition (e.g., visibility of element) is met the wait will stop and next statement will be executed.

Here is the sample method in java:

public void waitForScreenToLoad(AppiumDriver lDriver, WebElement element, int seconds){

```
          WebDriverWait wait = new WebDriverWait(lDriver,seconds);
          wait.until(ExpectedConditions.visibilityOf(element));

```

}

---

<div class="post-metadata">

**Author:** ![iRANG\_QA](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@iRANG\_QA](https://discuss.appium.io/u/iRANG_QA)\
**Post date:** [August 10, 2015, 3:23am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/4 "2015-08-10T03:23:08Z")

</div>

Okay , I followed this and now calling function like (waitForElementToLoad(driver, count ,60) , but now how can I integrate it with my condition? can you please explain in short that? My code is there in question for reference.

---

<div class="post-metadata">

**Author:** ![Umar\_Khan](https://discuss.appium.io/user_avatar/discuss.appium.io/umar_khan/32/6847_2.png) [@Umar\_Khan](https://discuss.appium.io/u/Umar_Khan)\
**Post date:** [August 10, 2015, 3:42pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/5 "2015-08-10T15:42:29Z")

</div>

What is ‘count’ that you are passing in the function as parameter? is it WebElement?

---

<div class="post-metadata">

**Author:** ![iRANG\_QA](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@iRANG\_QA](https://discuss.appium.io/u/iRANG_QA)\
**Post date:** [August 12, 2015, 5:03am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/6 "2015-08-12T05:03:45Z")

</div>

Hey,

It is solved… thanks a lot for support.

---

<div class="post-metadata">

**Author:** ![Umar\_Khan](https://discuss.appium.io/user_avatar/discuss.appium.io/umar_khan/32/6847_2.png) [@Umar\_Khan](https://discuss.appium.io/u/Umar_Khan)\
**Post date:** [August 12, 2015, 2:27pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/7 "2015-08-12T14:27:22Z")

</div>

Glad. Happy automation

---

<div class="post-metadata">

**Author:** ![Anuja\_Bhatt](https://discuss.appium.io/user_avatar/discuss.appium.io/anuja_bhatt/32/2847_2.png) [@Anuja\_Bhatt](https://discuss.appium.io/u/Anuja_Bhatt)\
**Post date:** [November 21, 2016, 7:12am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/8 "2016-11-21T07:12:59Z")

</div>

Hi . refer this tutorial to work with implicit and explicit wait with Appium  
WebDriverWait wait = new WebDriverWait(driver,20);  
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“about\_me”)));

> **[Implicit & Explicit Wait with Appium](http://www.qaautomated.com/2016/11/implicit-explicit-wait-with-appium.html)**
>
> Complete Appium Tutorial on How to use different types of wait in Appium like Implicit wait and Explicit Wait

---

<div class="post-metadata">

**Author:** ![anish10110](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@anish10110](https://discuss.appium.io/u/anish10110)\
**Post date:** [December 12, 2016, 5:04am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/9 "2016-12-12T05:04:31Z")

</div>

If you are using PageFactory model with Appium, then you can add implicit wait in InitElements() method as below -

`PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS), this);`

I have tried this with Appium 1.6 and it works fine.

---

<div class="post-metadata">

**Author:** ![VikramVI](https://discuss.appium.io/user_avatar/discuss.appium.io/vikramvi/32/116_2.png) [@VikramVI](https://discuss.appium.io/u/VikramVI)\
**Post date:** [February 15, 2017, 11:43am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/10 "2017-02-15T11:43:11Z")

</div>

@anish10110 can you please clarify if driver is of type WebDriver or AppiumDriver as in both case this is not working with latest java client

Thanks,  
Vikram

---

<div class="post-metadata">

**Author:** ![VikramVI](https://discuss.appium.io/user_avatar/discuss.appium.io/vikramvi/32/116_2.png) [@VikramVI](https://discuss.appium.io/u/VikramVI)\
**Post date:** [February 16, 2017, 9:21am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/11 "2017-02-16T09:21:15Z")

</div>

For the benefit of those who come to this post looking for answer like me, please find below info how I got it working

1\> Sample code

> <https://github.com/aws-samples/aws-device-farm-appium-tests-for-sample-app/blob/63a8b6f799d034fba39425b9a1f1fbe26eab6b91/src/test/java/Pages/BasePage.java>

2\> Refer to post for better info

> [@PageFactory PageObjectModel issues](https://discuss.appium.io/t/pagefactory-pageobjectmodel-issues/9822/2):
>
> we do it in another way. Base Page: public abstract class Page { protected WebDriver driver; public Page(WebDriver driver) { this.driver = driver; PageFactory.initElements(new AppiumFieldDecorator(driver, 30, TimeUnit.SECONDS), this); } } Page example: public class CallPage extends Page { //Action bar @AndroidFindBy(id = "homeButton") private List\<AndroidElement\> homeButton; @AndroidFindBy(id = "backButton") private List\<AndroidElement\> backBu…

3\> Found an issue wrt this

> <https://github.com/appium/java-client/issues/572>
>
> \## Description
> 
> I've set implicit wait for a page as below
> 
> \`\`\`
> protected W…ebDriver driver;
> 
> public AUTLandingPage(WebDriver driver) {
> this.driver = driver;
> PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS), this);
> }
> \`\`\`
> I also checked with AppiumDriver but same issue
> 
> In this pageobject class, I check for availability of element with method isEnabled()
> 
> \`particularElement.isEnabled()\`
> 
> But instead of waiting for 10 sec, driver just continues execution after 0 sec
> 
> \## Environment
> 
> \* java client build version or git revision if you use some shapshot: 5.0.0-BETA2
> \* Appium server version or git revision if you use some shapshot: 1.6.3
> \* Desktop OS/version used to run Appium if necessary: 
> \* Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: v7.2.1
> \* Mobile platform/version under test: iOS 10.2
> \* Real device or emulator/simulator: Simulator
> 
> \## Details
> 
> 1. This happens when I login and goto next screen.
> 2. Then this issue happens https://github.com/appium/appium/issues/7034
> 3. After this I've observed appium doesn't wait for default implicit time mentioned in constructor
> 
> \## Code To Reproduce Issue \[Good To Have \]
> 
> NA
> 
> \## Ecxeption stacktraces
> 
> NA
> 
> \## Link to Appium logs
> 
> NA

Regards,  
Vikram

---

<div class="post-metadata">

**Author:** ![satheesh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@satheesh](https://discuss.appium.io/u/satheesh)\
**Post date:** [August 7, 2017, 9:20am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/12 "2017-08-07T09:20:08Z")

</div>

Thanks …worked for me

---

<div class="post-metadata">

**Author:** ![ArpitJain](https://discuss.appium.io/letter_avatar_proxy/v4/letter/a/9f8e36/32.png) [@ArpitJain](https://discuss.appium.io/u/ArpitJain)\
**Post date:** [November 28, 2017, 5:30am UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/13 "2017-11-28T05:30:23Z")

</div>

It worked with latest jars:

Appium 1.7.1  
Java-client 5.0.4  
Selenium-java 3.7.1

AppiumDriver androidDriver will work

---

<div class="post-metadata">

**Author:** ![Kenneth\_Lewis](https://discuss.appium.io/user_avatar/discuss.appium.io/kenneth_lewis/32/12105_2.png) [@Kenneth\_Lewis](https://discuss.appium.io/u/Kenneth_Lewis)\
**Post date:** [November 7, 2023, 3:32pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/14 "2023-11-07T15:32:28Z")

</div>

I am using the WebDriverWait ExpectedConditions.presenseOfElement. But I find that if the element is not there the driver fails and the tests stops at that point. How can I wait for presence but if it doesn’t exists it should not fail but go to the next line of code.

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [November 7, 2023, 10:37pm UTC](https://discuss.appium.io/t/how-to-control-time-in-appium-when-find-element/5500/15 "2023-11-07T22:37:26Z")

</div>

You don’t say what language, but all have some kind of try/catch block for error handling.

Here’s an example in Java:

[https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html](https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html)
