#1.配置基本会话信息
# 基本会话信息
from appium import webdriver
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy
# For W3C actions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
options = AppiumOptions()
options.load_capabilities({
"platformName": "Android",
"appium:automationName": "UiAutomator2",
"appium:noReset": True,
"appium:skipDeviceInitialization": True,
"appium:ensureWebviewsHavePages": True,
"appium:nativeWebScreenshot": True,
"appium:newCommandTimeout": 3600,
"appium:connectHardwareKeyboard": True
})
driver = webdriver.Remote("http://127.0.0.1:4723", options=options)
#自动化代码区域
#例如:最常用的两个场景,点击和输入
#1.点击事件:
el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().description(\"浏览器\")")
el1.click()
#2.输入事件:
el2 = driver.find_element(by=AppiumBy.ID, value="com.android.browser:id/url") el2.send_keys("https://www.baidu.com/")
等待事件:
from time import sleep
sleep(2) #等待2s
截图事件:
driver.get_screenshot_as_file(f"{path}/1.png")
driver.quit()
需要掌握了解:
driver.