I am executing my scripts on android device. How can I put wait if the application doesn't support implicit wait or explicit wait? I'm using Thread.sleep()
in my case. Can anyone give me a solution for this?
Asked
Active
Viewed 141 times
2

Shahadat Hossain
- 533
- 7
- 20

monika durgude
- 21
- 1
-
I am executing scripts on android device. and i tried using webdriver wait with different conditions but for my app explicit waits and implicit wait is not working. Can anyone plz help me ? – monika durgude Jul 14 '19 at 04:17
-
Explicit and implicit waits are not supported by any application or site, those are Selenium features. Post the code that didn't work for you, the relevant html and the full error message. – Guy Jul 14 '19 at 04:33
2 Answers
2
Explicit Wait is not the feature of the application, it's the feature of Selenium which is under the hood of Appium
Therefore you should be normally able to use WebDriverWait and ExpectedConditions classes, see How to use Selenium to test web applications using AJAX technology for more information on the concept and code snippets:
WebDriverWait wait = new WebDriverWait(driver, 10);
MobileElement company = (MobileElement) wait
.until(ExpectedConditions
.elementToBeClickable(By
.id("usernameTextField")));
Full code with the necessary import statements just in case:
package com.example;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.URL;
public class AppiumTest {
public static void main(String[] args) throws Exception {
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.APP, "http://d242m5chux1g9j.cloudfront.net/eribank.apk");
dc.setCapability("platformName", "Android");
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.experitest.ExperiBank");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".LoginActivity");
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
dc.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), dc);
WebDriverWait wait = new WebDriverWait(driver, 10);
MobileElement company = (MobileElement) wait
.until(ExpectedConditions
.elementToBeClickable(By
.id("usernameTextField")));
company.sendKeys("company");
driver.quit();
}
}

Dmitri T
- 159,985
- 5
- 83
- 133
-
Thanks for your answer.I know it's selenium feature.But it's not working for my app on real android device. Webdriver wait i have put in my code.It's not working. IT won't wait and simply thrown exception .Element not located on this page.(Even Xpath was Correct) – monika durgude Jul 15 '19 at 06:09
0
This is a framework feature and not related to the app you are running it against. The wait needs you to tell it "How long it should wait?" in Milliseconds and What it should wait for?
#Time input
WebDriverWait wait = new WebDriverWait(driver, 50000);
#What to wait for
wait.until(ExpectedConditions.elementToBeClickable(By.id("usernameTextField")));

Sharaf
- 104
- 6