Appium自动化三
作者:互联网
使用手机浏览器测试百度搜索的一个实例
#coding:utf-8
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time,os
url=‘https://www.baidu.com’
desired_caps = {
‘platformName’: ‘Android’,
‘deviceName’: ‘3HX0217115011233’,
‘platformVersion’: ‘8’,
‘noReset’: True,
‘browserName’:‘Chrome’,
“newCommandTimeout”: “6000”
}
driver=webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
print(‘浏览器启动成功’)
driver.get(“http://www.baidu.com”)
#time.sleep(2)
#华为手机,会弹出个权限的系统提示框,执行两次回车动作可以取消掉。
driver.keyevent(66)
driver.keyevent(66)
try:
WebDriverWait(driver,10,1).until(lambda x:x.find_element_by_xpath("//input[@id=‘index-kw’]")).send_keys(“小鬼当家”)
time.sleep(5)
driver.keyevent(66)
except Exception as err:
pass
driver.keyevent(66)
time.sleep(5)
assert “小鬼当家” in driver.page_source
driver.close_app()
标签:Appium,keyevent,自动化,driver,sleep,66,time,import 来源: https://blog.csdn.net/eric3012/article/details/119489670