无法在 appium 中找到定位器 python

Not able to find locator in appium python

I am new to appium python client and need your suggestions to solve my below issue.PFA uiautomator viewer screen shot.Not 确定是否是这个原因:在电子邮件字段中输入后,会打开一个键盘,因此找不到密码和登录按钮 我已经下载了一个免费示例 xxx.apk 并创建了以下脚本来测试它:

class CareZoneAndroidTests(unittest.TestCase):
    "Class to run tests against the Care Zone app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.2'
        desired_caps['deviceName'] = 'Android Emulator'
        # Returns abs path relative to this file and not cwd
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'D:/Programs/myapp/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
        desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
        desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        "Tear down the test"
        self.driver.quit()

    def test_login(self):
        "Test the Login Page launches correctly"
        self.driver.implicitly_wait(120)
        print "After WAIT----------------->>>>>>>"
        #Click on Sign in button
        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_toolbar_action")
        self.driver.implicitly_wait(15)
        element.click()
        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")
        self.driver.implicitly_wait(10)
        element.click()
        element.send_keys("abc@ini.com");
        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
        element.click()
        element.send_keys("abc");
        self.driver.implicitly_wait(10)
        #element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")
        #element = self.driver.find_element_by_accessibility_id('Sign In')
        element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")')
        element.click()

问题:

test_login (main.CareZoneAndroidTests) Test the Login Page launches correctly ... After WAIT----------------->>>>>>> ERROR

====================================================================== ERROR: test_login (main.CareZoneAndroidTests) Test the Login Page launches correctly ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\Programs\myapp\CareZoneTests.py", line 42, in test_login element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")') File "D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver.py", line 133, in find_element_by_android_uiautomator return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string) File "D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element 'value': value})['value'] File "D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "D:\Programs\Python275\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response raise wde NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

在下面尝试过,但都因同样的原因而失败:

尝试按 ID 查找元素:

  • 元素=self.driver.find_element_by_id('Sign In')

已更新:

尝试在执行选择元素的操作之前放置 hidekeyboard(); 以隐藏您的键盘!

下面的代码对我来说很好用:

class CareZoneAndroidTests(unittest.TestCase):
    "Class to run tests against the Care Zone app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.2'
        desired_caps['deviceName'] = 'Android Emulator'
        # Returns abs path relative to this file and not cwd
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'D:/Programs/myapp/CareZone_v6.6.0.0 (flagship)_apkpure.com.apk'))
        desired_caps['appPackage'] = 'com.carezone.caredroid.careapp.medications'
        desired_caps['appActivity'] = 'com.carezone.caredroid.careapp.ui.activity.LandingActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        "Tear down the test"
        self.driver.quit()

    def test_login(self):
        "Test the Login Page launches correctly"
        self.driver.implicitly_wait(120)
        print "Sign in Page"
        element = self.driver.find_element_by_xpath("//android.widget.TextView[@text='Have an account? Sign In']")
        self.driver.implicitly_wait(15)
        element.click()

        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_mail_edit")

        element.click()
        element.send_keys("ja.i@c.com");
        self.driver.implicitly_wait(3)
        self.driver.keyevent(61)

        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_password_edit")
        element.click()
        element.send_keys("ni");
        self.driver.implicitly_wait(3)
        print "Click TABS 2 times to get Sign In button-->>>>>>>"
        self.driver.keyevent(61)
        self.driver.keyevent(61)


        element = self.driver.find_element_by_id("com.carezone.caredroid.careapp.medications:id/welcome_page_sign_bton")

        element.click()
        self.driver.implicitly_wait(120)
        print "TEST OK"