gpt4 book ai didi

python - 无法在 appium python 中找到定位器

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:44 25 4
gpt4 key购买 nike

enter image description here我是 appium python 客户端的新手,需要您的建议来解决我的以下问题。PFA uiautomator 查看器 enter image description here屏幕截图。不确定这是否是原因:在电子邮件字段中输入内容后,键盘会打开,因此找不到密码和登录按钮我已经下载了一个免费的示例 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.

尝试了以下方法,但由于相同的原因都失败了:

  • 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('newUiSelector().text("登录")')

最佳答案

尝试通过 ID 查找元素:

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

更新:

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

关于python - 无法在 appium python 中找到定位器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com