1

I'm working on writing a test automation script for a android app.

I'm using python to write the code and using Appium server to run these tests and using Appium UI inspector to identify elements.

I'm testing on a button for which i got the id from Appium UI inspector but on running the script fails at the point where the code is trying to identify the button.

python script

el_createConfBtn = self.driver.find_element("id", "**.**.app:id/btnSubmit")

Appium UI inspector enter image description here

error

selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

enter image description here

was trying to click on the button. the expectation is Appium identifies the element and then run the code without failing

mali abey
  • 11
  • 2
  • Given that the error message tells you `NoSuchElementException` can you confirm that the element actually exists ? "*An element could not be located on the page using the given search parameters*" – D.L Dec 08 '22 at 09:18
  • This element exists and has a unique id – mali abey Dec 08 '22 at 10:10
  • if the element exists, then the search is deficient. Please share sufficient code for others to help identify the error and fix: https://stackoverflow.com/help/minimal-reproducible-example – D.L Dec 08 '22 at 10:15

2 Answers2

0

Does it work when you write an xpath selector like //android.widget.Button[@resource-id='yourid']?

Are you sure the button is loaded/clickable yet when you're trying to click?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
valies
  • 96
  • 5
0

The main thing
The screenshot that you attached shows resource-id not ID, therefore, most likely, an error occurs, accordingly you should use XPath
It will be better to use AppiumBy.ID instead "id", as well

  el_createConfBtn = self.driver.find_element(AppiumBy.XPATH, "locator")

Simple example:

class BaseClass:
  
  
  def click(self, locator: Tuple[By, str]):
      self.driver.find_element(*locator).click()

class PO(BaseClass):
      EL_LOCATOR = (AppiumBy.ID, "**.**.app:id/btnSubmit")

   def tap_on_btn(self):
       self.click(self.EL_LOCATOR)


___________________

def tap(self, locator):
        try:
            locator = self.wait.until(
                ec.visibility_of_element_located(locator))
            locator.click()
        except NoSuchElementException:
           print('')


___________________

  def click(self, locator_string):
    locator = self.get_locator(locator_string)
    if str(locator_string[0]).startswith("xpath"):
        self.driver.find_element(MobileBy.XPATH, str(locator)).click()
    elif str(locator_string[0]).startswith("accessibility"):
        self.driver.find_element(MobileBy.ACCESSIBILITY_ID, str(locator)).click()

def get_locator(locator_with_type):
    locator = locator_with_type[1]
    return locator