【Python + Appium】之元素定位總結(待更新)
阿新 • • 發佈:2020-08-07
一、ID定位
uiautomatorviewer裡面的:resource-id
driver.find_element(By.ID,"com.csks.businesses:id/tv_number").click()
二、利用index角標定位
# 利用index角標定位 # 獲取多個輸入框 inputs = driver.find_elements(By.CLASS_NAME,"android.widget.EditText") # 第一個輸入框 inputs[0].send_keys("18602603xxx") # 第二個輸入框 inputs[1].send_keys("123123")
三、class定位
# className定位(但是不準) driver.find_element(By.CLASS_NAME,"android.widget.TextView").send_keys("18602603XXX")
四、XPATH定位
①text定位
# Xpath,利用text定位 driver.find_element(By.XPATH,"//*[@text='DD20200422000001']").click()
②組合定位(text與id)
# Xpath,利用組合定位 driver.find_element(By.XPATH,"//*[@text='請輸入密碼' and @resource-id='com.csks.businesses:id/edt_password']").send_keys("123123")
五、座標定位
# 點選頁面的座標 driver.tap([(274, 271), (650, 319)], 500)
六、尋找元素,並點選元素
def swipeUp(): '向上滑動' width = driver.get_window_size()['width'] height = driver.get_window_size()['height'] driver.swipe(1/2*width,4/5*height,1/2*width,1/5*height) # 尋找元素,並點選while 1<10: try: # 模糊定位 driver.find_element(By.XPATH,"//*[contains(@text,'規格描述:276373')]").click() break except: print("未找到,繼續上滑") swipeUp()
七、模糊定位
# 模糊定位 driver.find_element(By.XPATH,"//*[contains(@text,'規格描述:276373')]").click()