自动化计算器加乘用xpath 实现

这篇博客展示了如何利用Appium和XPath在Android设备上自动化执行加法和乘法计算。通过定位计算器应用的不同数字按钮和运算符,进行点击操作,最后获取并清理结果文本。

coding:UTF-8

@Shan-shan xu

from appium import webdriver
import time,traceback
desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘platformVersion’] = ‘5.1’
desired_caps[‘deviceName’] = ‘test’

desired_caps[‘app’] = r’F:\apk\com.ibox.calculators_3.0.3_1303.apk’

desired_caps[‘appPackage’] = ‘com.ibox.calculators’
desired_caps[‘appActivity’] = ‘com.ibox.calculators.SplashActivity’
desired_caps[‘unicodeKeyboard’] = True
desired_caps[‘noReset’] = True
desired_caps[‘newCommandTimeout’] = 6000
driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
driver.implicitly_wait(10)
try:
num3 = driver.find_element_by_id(‘com.ibox.calculators:id/digit3’)
num9 = driver.find_element_by_id(‘com.ibox.calculators:id/digit9’)
num5 = driver.find_element_by_id(‘com.ibox.calculators:id/digit5’)
plus = driver.find_element_by_id(‘com.ibox.calculators:id/plus’)
equal = driver.find_element_by_id(‘com.ibox.calculators:id/equal’)
mul = driver.find_element_by_id(‘com.ibox.calculators:id/mul’)
num3.clear()
plus.clear()
num9.clear()
equal.clear()
mul.clear()
num5.clear()
equal.clear()
xpath = ‘//*[@resource-id=“com.ibox.calculators:id/cv”]/android.widget.TextView[2]’
ele = driver.find_element_by_xpath(xpath)

retStr = ele.text
print(retStr)
if retStr == '60':
    print('pass')
else:
    print('fail!')

except:
print(traceback.format_exc())

input(’**** Press to quit…’)
driver.quit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值