I can't get WebDriverWait to work

Hi
i am trying to explicit wait for every locators. Using iOS and Android.
if any id/locator is not available , its running forever. giving below error:

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] Waited for 4875 ms so far
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] Matched ‘/element’ to command name ‘findElement’
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/62b67ba5-6118-4abf-8b55-8e5f69b059a0/element] with body: {“strategy”:“xpath”,“selector”:"//*[@text=‘xxxxxxx’]",“context”:"",“multiple”:false}
[AndroidUiautomator2Driver@adaa (f21ff45e)] Got response with status 404: {“sessionId”:“62b67ba5-6118-4abf-8b55-8e5f69b059a0”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.utils.ElementLocationHelpers.findElement(ElementLocationHelpers.java:156)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:60)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.Abstr…
[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] at AndroidUiautomator2Driver.findElOrEls (/Users/xxx/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:75:11)
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] at processTicksAndRejections (node:internal/process/task_queues:95:5)
[debug] [AndroidUiautomator2Driver@adaa (f21ff45e)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-

my code snippet :

In tried both : none of them working

public void waitForElementToBeClickable(WebElement ele) throws InterruptedException {

	try {
		WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
		wait.until(ExpectedConditions.elementToBeClickable(ele));
		

		

	} catch (Throwable e) {
		System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());

	} 

}

Also :

public WebElement waitForElementToBeClickable(WebElement ele) throws InterruptedException {

	try {
	
		WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
		wait.until(ExpectedConditions.elementToBeClickable(ele));
		return ele;



	} catch (Throwable e) {
		System.out.println("Unable to wait and click on element, Exception: " + e.getMessage());

	} finally {
		System.out.println("*******************************abc*******************");
	}


	return ele;
}

Config :
~ appium -v
2.1.3
➜ ~ npm -version
10.1.0

➜ ~ java -version
openjdk version “17.0.8.1”
OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.8.1+1 (build 17.0.8.1+1, mixed mode)

Summary

This text will be hidden

5 sec you calling forever?

It is not clear what wrong? You cant find element? You wait more then configured 20sec?

when element is not available its running forever.
It should wait for 20 sec and after that it should fail the testcase.
right now it not failing, its keep running and try to find same element

[HTTP] {“using”:“id”,“value”:“android:id/button21”}

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Calling AppiumDriver.findElement() with args: [“id”,“android:id/button21”,“d4564dee-b509-4530-832e-5fec49ae8baf”]

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waiting up to 5000 ms for condition

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/4904a447-4c84-4ffc-afcf-6cde69cefcf5/element] with body: {“strategy”:“id”,“selector”:“android:id/button21”,“context”:"",“multiple”:false}

[AndroidUiautomator2Driver@166d (d4564dee)] Got response with status 404: {“sessionId”:“4904a447-4c84-4ffc-afcf-6cde69cefcf5”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann…

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waited for 767 ms so far

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/4904a447-4c84-4ffc-afcf-6cde69cefcf5/element] with body: {“strategy”:“id”,“selector”:“android:id/button21”,“context”:"",“multiple”:false}

[AndroidUiautomator2Driver@166d (d4564dee)] Got response with status 404: {“sessionId”:“4904a447-4c84-4ffc-afcf-6cde69cefcf5”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann…

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waited for 2089 ms so far

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/4904a447-4c84-4ffc-afcf-6cde69cefcf5/element] with body: {“strategy”:“id”,“selector”:“android:id/button21”,“context”:"",“multiple”:false}

[AndroidUiautomator2Driver@166d (d4564dee)] Got response with status 404: {“sessionId”:“4904a447-4c84-4ffc-afcf-6cde69cefcf5”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann…

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waited for 3373 ms so far

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/4904a447-4c84-4ffc-afcf-6cde69cefcf5/element] with body: {“strategy”:“id”,“selector”:“android:id/button21”,“context”:"",“multiple”:false}

[AndroidUiautomator2Driver@166d (d4564dee)] Got response with status 404: {“sessionId”:“4904a447-4c84-4ffc-afcf-6cde69cefcf5”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann…

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waited for 4631 ms so far

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/4904a447-4c84-4ffc-afcf-6cde69cefcf5/element] with body: {“strategy”:“id”,“selector”:“android:id/button21”,“context”:"",“multiple”:false}

[AndroidUiautomator2Driver@166d (d4564dee)] Got response with status 404: {“sessionId”:“4904a447-4c84-4ffc-afcf-6cde69cefcf5”,“value”:{“error”:“no such element”,“message”:“An element could not be located on the page using the given search parameters”,“stacktrace”:"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:63)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.chann…

[debug] [W3C] Matched W3C error code ‘no such element’ to NoSuchElementError

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] at AndroidUiautomator2Driver.findElOrEls (/Users/xxxxx/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/find.js:75:11)

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] at processTicksAndRejections (node:internal/process/task_queues:95:5)

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:60:12)

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] at AndroidUiautomator2Driver.findElement (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/commands/find.ts:75:12)

[HTTP] <-- POST /session/d4564dee-b509-4530-832e-5fec49ae8baf/element 404 5826 ms - 823

[HTTP]

[HTTP] --> POST /session/d4564dee-b509-4530-832e-5fec49ae8baf/element

[HTTP] {“using”:“id”,“value”:“android:id/button21”}

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Calling AppiumDriver.findElement() with args: [“id”,“android:id/button21”,“d4564dee-b509-4530-832e-5fec49ae8baf”]

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Waiting up to 5000 ms for condition

[debug] [AndroidUiautomator2Driver@166d (d4564dee)] Matched ‘/element’ to command name ‘findElement’

This is Selenium functionality, not Appium. Appium just search.

Try examples https://www.selenium.dev/documentation/webdriver/waits/