NoSuchElementException: An element could not be located on the page using the given search parameters

Hello,

I am facing this issue when the following code is being executed. But this is not consistent. Sometimes the element is returned with no error. Sometimes the error is throwing. We are using pytest and WinAppDriver for automation of a win32 application.

Using :

  • Appium-Python-Client Ver 1.3.0

  • Pytest Ver 7.1.2

  • WinAppDriver v1.2.1

      def click_element_in_toolbar(self, element_index):
          """Click element in the toolbar"""
          review_window_toolbar_children = self.driver.find_element_by_accessibility_id(REVIEW_WINDOW_TOOLBAR_ID).find_elements_by_xpath(ALL_CHILDREN_PATH)
          time.sleep(2)
          review_window_toolbar_children[element_index].click()

Sounds like there may be some kind of transition state in the app (like a screen change). These states are usually addressed with an explicit wait. Here is an example in Python: