python寫appium測試用例找控制元件的方法總結
appium的webdriver繼承了selenium中的webdriver,因此這些方法都可以在selenium的\py\selenium\webdriver\remote\webdriver.py檢視到
執行一個appium的程式:python appium_test.py 即可
appium測試指令碼的一個簡單例子:
一、獲取整個頁面的XML文字
可以把當前頁面的元素以XML的方式打印出來,在找不到view的相應屬性的時候就呼叫該函式來慢慢查詢
driver.getPageSource()
二、獲取頁面元素或資訊
1、通過id查詢元素:driver.find_element_by_id('com.xxx.test:id/phone_bind')
2、通過文字查詢元素:driver.find_element_by_name('意見反饋')
3、獲取頁面所有可見元素並返回為一個數組:driver.find_elements_by_xpath('//*')
4、通過xpath獲取頁面指定元素:driver.find_element_by_xpath('//android.widget.LinearLayout[@resource-id='com.yixia.videoeditor:id/o_']/android.widget.TextView')
4、獲取當前頁面activity:driver.current_activity
向獲取到的textview輸入文字:
textview.send_keys('abcd')
driver.press_keycode(4) 其中的4代表的是返回按鈕
獲取元素的屬性,文字:
driver.find_element_by_id('com.yixia.videoeditor:id/dialog_right_buton')..get_attribute("text") #獲取按鈕的文字屬性