【appium 安卓10 QQ发送消息】

代码

python 复制代码
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 Capabilities
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
}

# 创建 Appium WebDriver 实例
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("已成功输入 '你夏哥'")

    # 等待并点击 ID 为 com.tencent.mobileqq:id/dpr 的元素
    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("已成功点击消息发送框")

    # 输入消息 "Hello World!"
    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
相关推荐
booboosui3 小时前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白19 小时前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android1 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m1 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui1 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
用户60709759149061 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭1 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
JMchen1231 天前
【Android 性能优化实战 60 讲】12 异步 Inflate 实战与痛击:源码拆解原生瓶颈,手写增强版布局预加载框架
android·性能优化·实战·启动优化·异步inflate·x2c
好的佩奇2 天前
蓝牙之设备角色与连接
android·flutter·蓝牙
雨白2 天前
Android 消息机制剖析:从 Handler 投递到 Looper 循环的全链路
android