代码
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
desired_caps = {
"platformName": "Android",
"platformVersion": "10.0",
"deviceName": "Android Emulator",
"appPackage": "com.tencent.mobileqq",
"appActivity": ".activity.SplashActivity",
"automationName": "UiAutomator2",
"noReset": True,
"appium:ignoreHiddenApiPolicyError": True,
"appium:forceAppLaunch": True
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
try:
search_box = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "com.tencent.mobileqq:id/et_search_keyword"))
)
search_box.click()
print("已成功点击搜索输入框")
search_box = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "com.tencent.mobileqq:id/et_search_keyword"))
)
search_box.send_keys("你夏哥")
print("已成功输入 '你夏哥'")
target_element = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "com.tencent.mobileqq:id/dpr"))
)
target_element.click()
print("已成功点击你夏哥")
input_box = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "com.tencent.mobileqq:id/input"))
)
input_box.click()
print("已成功点击消息发送框")
input_box.send_keys("Hello World!")
print("已成功输入消息 'Hello World!'")
send_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "com.tencent.mobileqq:id/fun_btn"))
)
send_button.click()
print("已成功点击发送按钮")
except Exception as e:
print(f"操作失败: {e}")
finally:
pass