Search code examples
automated-testsappiumappium-android

Find Element AppiumBy.ID "com.google.android.calculator:id/formula" - element could not be located


I want to get the calculator result by following code but it throw NoSuchElementError. I have tested to find by XPath. It is same error.

driver.find_element(AppiumBy.ID, "com.google.android.calculator:id/formula")

Code:

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

# For W3C actions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput

caps = {}
caps["platformName"] = "Android"
caps["appium:ensureWebviewsHavePages"] = True
caps["appium:nativeWebScreenshot"] = True
caps["appium:newCommandTimeout"] = 3600
caps["appium:connectHardwareKeyboard"] = True
caps["appPackage"] = "com.google.android.calculator"
caps["appActivity"] = "com.android.calculator2.Calculator"

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)


el1 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="7")
el1.click()
el2 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="plus")
el2.click()
el3 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="8")
el3.click()
el4 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="equals")
el4.click()

re = driver.find_element(AppiumBy.ID, "com.google.android.calculator:id/formula")
print(re.text)

driver.quit()

Appium Inspector

Thanks Wilson


Solution

  • I found that it should be

    re = driver.find_element(AppiumBy.ID, "com.google.android.calculator:id/result_final")
    

    Appium Inspector

    Thanks Wilson