我是appium python客户的新手,需要你的建议来解决我的下面的问题.PFA uiautomator viewer 屏幕截图。不确定这是否是原因:输入电子邮件字段后,键盘打开,因此找不到密码和登录按钮 我已经下载了一个免费的样本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)测试登录页面 正确启动...等待WAIT ----------------->>>>>>> ERROR
=============================================== =======================错误:test_login( main .CareZoneAndroidTests)测试登录页面 正确启动 -------------------------------------------------- -------------------- Traceback(最近一次调用最后一次):文件 test_login中的“D:\ Programs \ myapp \ CareZoneTests.py”,第42行 element = self.driver.find_element_by_android_uiautomator('new UiSelector()。text(“Sign In”)')File “d:\程序\ Python275 \ LIB \站点包\ appium \ webdriver的\ webdriver.py” 第133行,在find_element_by_android_uiautomator中 return self.find_element(by = By.ANDROID_UIAUTOMATOR,value = uia_string)File “d:\程序\ Python275 \ LIB \站点包\硒\ webdriver的\遥控\ 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中 raise wde NoSuchElementException:消息:使用给定的搜索参数无法在页面上找到元素。
在下面尝试过,但由于同样的原因,所有人都失败了:
element = self.driver.find_element_by_android_uiautomator('new UiSelector()。text(“登录”)')
答案 0 :(得分:1)
尝试按ID查找元素:
更新:
在执行选择元素的操作之前尝试放置hidekeyboard();
以隐藏键盘!
答案 1 :(得分: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"