// Create an instance of the AndroidDriver and set up desired capabilities AndroidDriver<MobileElement> driver = new AndroidDriver<>(appiumServerUrl, desiredCapabilities); // Define the explicit wait with a timeout of 10 seconds WebDriverWait wait = new WebDriverWait(driver, 10); // Wait for an element to be visible MobileElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.id("myElementId"))); // Perform actions on the element once it is visible element.click(); ////////////// System.out.println("Numbers: "); String elementText = "بستن"; By byText = MobileBy.AndroidUIAutomator("new UiSelector().text(\"" + elementText + "\")"); WebElement closeButton = null; try { closeButton = driver.findElement(byText); } catch (NoSuchElementException e) { // Element not found, do nothing } if (closeButton != null) { closeButton.click(); }