Appium常用元素定位方式
获取元素的文本内容
方法:text
ly = driver.find_element_by_xpath("//*[contains(@text,'蓝牙')]")
print(ly.get_attribute("displayed"))
获取元素在屏幕上的坐标
方法:location
zb = driver.find_element_by_id("com.android.settings:id/search")
print(zb.location)
swip滑动事件
driver.swipe(184,1158,184,478,5000)
scroll滑动事件
el1 = driver.find_element_by_xpath("//*[contains(@text,'存储')]")
el2 = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
driver.scroll(el1,el2)
drag拖拽事件
el1 = driver.find_element_by_xpath("//*[contains(@text,'存储')]")
el2 = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
driver.drag_and_drop(el1,el2)
手指轻敲操作
el = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
TouchAction(driver).tap(el).perform
手指按操作
el = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
TouchAction(driver).press(el).release().perform()
等待操作
方法:wait
driver.find_element_by_xpath("//*[contains(@text,'WLAN')]").click()
el = driver.find_element_by_id("android:id/title")
TouchAction(driver).press(el).wait(5000).perform()
手指长按操作
driver.find_element_by_xpath("//*[contains(@text,'WLAN')]").click()
el = driver.find_element_by_id("android:id/title")
TouchAction(driver).long_press(el,duration=5000).release().perform()
手指移动操作
el = driver.find_element_by_xpath("//*[contains(@text,'存储')]")
ell = driver.find_element_by_xpath("//*[contains(@text,'更多')]")
TouchAction(driver).press(el).move_to(ell).release().perform()