appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
440 stars 179 forks source link

Cannot find item with By.Id in android into popup request permission in android device #654

Closed apatheticL closed 5 months ago

apatheticL commented 5 months ago

I have a problem when i call function find_element(By.Id, 'com.android.permissioncontroller:id/permission_allow_button') then it show error in this link https://gist.github.com/apatheticL/0bea475d440c2e99c0a42fd350081205 this is my code my base function

def find_element(self, locator):
        print(locator)
        try:
            return self.driver.find_element(*locator)
        except:
            self.handle_exception()
            # self.find_element(locator)
            return self.driver.find_element(*locator)

   def find_element_and_click(self, locator):
        print("click")
        try:
            self.find_element(locator).click()
        except:
            self.handle_exception()
            self.find_element(locator).click()

my call function

    continue_button = (By.ID, 'com.android.permissioncontroller:id/permission_allow_button')
            self.find_element_and_click(self.continue_button)

value of seft send into base funtion is

/// library 
from appium.webdriver import Remote
from appium.webdriver.webdriver import WebDriver 

 clss.driver = Remote('http://localhost:4723', options=capabilities_options)

Please help me fix it. Thank so much.

KazuCocoa commented 5 months ago

I would switch the context to interact with elements outside Flutter https://github.com/appium/appium-flutter-driver?tab=readme-ov-file#context-management

apatheticL commented 5 months ago

Thank you, but I want to know what I should do now to pass this error. I'm waiting for you to update the new version of the library or do I need to fix anything in my code? I looked at the example in this link https://github.com/appium/appium-flutter-driver/tree/main/example (python) but couldn't find the config section to change the context

KazuCocoa commented 5 months ago

It is client side update only.

For python, https://github.com/appium/python-client/blob/92583ce39003b740bb5e57bbf2114d283d884d22/test/functional/android/context_switching_tests.py#L68 is the usage to switch the context. https://appium.github.io/python-client-sphinx/webdriver.html#webdriver.switch_to.MobileSwitchTo.context

You would need to switch the context with NATIVE_APP to interact with non-Flutter elements before interacting with them since system permission is out of control by Flutter.

apatheticL commented 5 months ago

Thank so much. My problem is fixed.