1

在此处输入图像描述我是 appium python 客户端的新手,需要您的建议来解决我的以下问题。PFA uiautomator 查看器在此处输入图像描述屏幕截图。不确定这是否是原因:在输入电子邮件字段后,会打开一个键盘,因此找不到密码和登录按钮我已经下载了一个免费的示例 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_login(主要.CareZoneAndroidTests) 测试登录页面是否正确启动 ----------------------------------------- ----------------------------- 回溯(最近一次通话最后):文件“D:\Programs\myapp\CareZoneTests.py” ,第 42 行,在 test_login element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Sign In")') 文件“D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver. py”,第 133 行,在 find_element_by_android_uiautomator 返回 self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string) 文件“D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”,行752,在 find_element 'value': value})['value'] 文件“D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 236 行,在执行 self.error_handler.check_response(response) 文件“D:\Programs\Python275\lib\site-packages\appium\webdriver\errorhandler.py”,第 29 行,在 check_response 中引发 wde NoSuchElementException:消息:使用给定的搜索参数无法在页面上找到元素。

在下面尝试过,但由于相同的原因都失败了:

  • 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('登录')

  • element = self.driver.find_element_by_android_uiautomator('new UiSelector().text("登录")')

4

2 回答 2

1

尝试按 ID 查找元素:

  • element = self.driver.find_element_by_id('登录')

更新 :

尝试hidekeyboard();在选择元素之前放置一个元素以隐藏您的键盘!

于 2017-03-06T09:20:00.103 回答
0

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

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"
于 2017-03-13T11:21:38.720 回答