dcsxlh

导航

 
from appium import webdriver    #导入appium库
from time import sleep
cps={ #匹配模拟器和App
"platformName":"Android",
"deviceName":"127.0.0.1:62001",
"platformVersion":"4.4.2",
"appPackage":"com.baidu.yuedu",
"appActivity":"com.baidu.yuedu.splash.SplashActivity",
"unicodeKeyboard":"True",
"resetKeyboard":"True",
"noReset":"True"
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",cps) #运行模拟器和app
# #代码脚本和服务端是通过 http://127.0.0.1:4723/wd/hub 来进行通信的(固定格式)
sleep(8) #延迟时间
==============================================================================================================
定位
#1)通过 id 定位:
#driver.find_element_by_id("com.baidu.yuedu:id/negativeUpgrade").click()# 取消按钮
举例:
id:com.baidu.yuedu:id/negativeUpgrade

#2)通过 xpath 定位:

#driver.find_element_by_xpath('//android.widget.TextView[@text="取消"]').click()
#driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.baidu.yuedu:id/negativeUpgrade']").click()

举例:
xpath://android.widget.TextView[@resource-id='com.baidu.yuedu:id/negativeUpgrade']

 

 





# #3)通过 xpath 组合定位:
# driver.find_element_by_xpath('//android.widget.TextView[@text="取消"and@resource-id="com.baidu.yuedu:id/negativeUpgrade"]').click()

举例:

 

 注意:加了@text="取消"

# #4)通过UIautomator中的text文本定位:
#driver.find_element_by_android_uiautomator('new UiSelector().text("取消")').click()
#5)通过UIautomator中的text 包含部分文本内容定位:
#driver.find_element_by_android_uiautomator('new UiSelector().textContains("取")').click()
#6)通过UIautomator中的text 以某个字符串开头进行定位:
driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("取")').click()
# sleep(6)
driver.find_element_by_id("com.baidu.yuedu:id/tab_search").click()
sleep(6)
# # 8)输入
driver.find_element_by_xpath('//android.widget.EditText[@text="搜书架或书城"]').send_keys("坏蛋是怎样练成的")
sleep(2)
# #9)搜索
driver.find_element_by_id("com.baidu.yuedu:id/full_text_search_bar_search").click()
sleep(6)
driver.quit() #运行模拟器和app
#=================================================================================================================

posted on 2020-12-30 16:43  多测师_肖sir  阅读(228)  评论(0编辑  收藏  举报