? 現(xiàn)在開發(fā)的前端界面使用vue或者更牛逼技術(shù),導(dǎo)致使用appium或者uiautomator2做自動化測試時不能識別到元素,無法使用傳統(tǒng)的id,name或者xpath,這時我們需要使用坐標(biāo)點(diǎn)擊文本框。有獲取坐標(biāo)方法,下期寫一篇文章,可以在評論區(qū)提醒瑞克。
from appium import webdriver import time import os import subprocess from config import setting from paddleocr import PaddleOCR import pyautogui from selenium.webdriver.common.utils import keys_to_typing from selenium.webdriver.common.by import By from selenium.webdriver.remote.webelement import WebElement from utils.inputMethod import InputMethod from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.common.multi_action import MultiAction desired_caps = dict() desired_caps['platformName'] = 'Android' # 可以寫成android desired_caps['platformVersion'] = '12' # 11.1.0等都可以寫成11 desired_caps['deviceName'] = 'HONOR X10' # 設(shè)備名字可以隨便寫,但是不可以為空 desired_caps['appPackage'] = '你測試app包名' desired_caps['appActivity'] = '你測試app的MainActivity' desired_caps['noReset'] = True # 打開app時不清除數(shù)據(jù) desired_caps['udid'] = "你手機(jī)id" desired_caps['unicodeKeyboard'] = True desired_caps['resetKeyboard'] = True #啟動appium服務(wù) # cmd = r'start appium -a 127.0.0.1 -p 4723 -bp 4724' # pr = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) # pr.wait(timeout=3) driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) time.sleep(10) # 等待20秒"
#在焦點(diǎn)輸入框輸入瑞克
driver.switch_to.active_element.send_keys("瑞克") # 輸入文本
?測試實(shí)現(xiàn)效果圖:
文章來源:http://www.zghlxwxcb.cn/news/detail-434821.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-434821.html
到了這里,關(guān)于(第一篇,踩坑無數(shù)得來的,對Ai自動化測試框架很有幫助)appium自動化測試時遇到不能使用element定位的在用坐標(biāo)點(diǎn)擊之后獲取焦點(diǎn)如何輸入文本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!