FluentWait with iOS application on Real Device

Hi All.

I need to make the script wait until element is present in UI level.For this I have done below snippet:

FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
				.withTimeout(45, TimeUnit.SECONDS)//Sets how long to wait for the evaluated condition to be true.
				.pollingEvery(2, TimeUnit.SECONDS)//Sets how often the condition should be evaluated.
				//Configures this instance to ignore specific types of exceptions while waiting for a condition.
				.ignoring(NoSuchElementException.class).ignoring(NoSuchFieldException.class)
				.withMessage("Time expired");
		WebElement webElement = wait.until(new Function<WebDriver,WebElement>(){
				public WebElement apply(WebDriver arg0) {
					return driver.findElementByAccessibilityId("Form");}
				});
		webElement.click();//Click if element is present after 45 secs..else throw exception(NoSuchElement)

The problem am facing is that,the driver doesn’t even wait for the specified time(45 secs) in the FluentWait instance.Correct me if anything wrong in the above Snippet.

Is there any alter way for Thread.sleep method other than ExpectedConditions class.

Do you know the difference between seconds and milliseconds? Try setting the value to 45000.

Here is a converter for you to use:

Thanks for the reply @wreed!!
I have edited the question.

Did you run it, and did it work? I’m assuming that was just a copy/paste from your code.

Yes @wreed!!!

Made some changes in the Code!!! :slight_smile:

1 Like

I am using the same code as above to find an element.Below is the code which i am using:

Wait wait = new FluentWait((IOSDriver) device.getDriver())
.withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(250, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);

	foo = wait.until(new Function<IOSDriver, IOSElement>() {
		public IOSElement apply(IOSDriver driver) {
			IOSElement x = (IOSElement) driver.findElement(By.id("id"));
			if(!(x.isEnabled())){
				x = null;
			}
			return x;
		}
	});

The presence of the element, i am trying to find is uncertain, sometimes it is present and sometimes it isn’t. So if it is present i want to handle it and if it isn’t i want to ignore that element without throwing Exception “NoElementFoundException” which is what Fluent wait is expected to do. While execution, the driver waits for the element for 10 seconds and after that throws the “NoElementFoundException” which ruins the whole idea of using FluentWait as i have already given this exception in ignoring condition. I am trying to run this code for an ios app on real ios device. Any help will be appreciated. I have also checked that i have added correct Exception classes
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;