微信小程序(h5锲套)定位元素问题

1、第一步

微信内H5页面调试需要将调试模式打开,微信任意聊天框http://debugmm.qq.com/?forcex5=true
http://debugx5.qq.com
点击信息,勾选打开调试功能

2、第二步

下载谷歌对应的驱动,打开chrome浏览器,地址栏输入 chrome://inspect ,出现如下所示界面
在这里插入图片描述
https://chromedriver.storage.googleapis.com/index.html,浏览器驱动下载地址。下载了对应的驱动后,以前的驱动可以新建一个文件夹放着,然后再到appium里面去填写驱动的路径。

小程序只能用xpath定位!!!

3、第三步

有h5锲套的APP或者小程序,要下载uc开发者工具,直接百度即可。
h5锲套的直接用uc开发者工具进行元素定位即可。直接右键复制xpath定位。跟浏览器上的f12一样。

from appium import webdriver
from time import sleep as s
from Testcase.homepage import HomePage
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
# from selenium.common.exceptions import NoSuchElementException
#手机的信息
desired_caps = {
    "devicesName": "FFK0217724002496",
    "platformName": "Android",
    "platformVersion": "9",
    "appPackage": "com.tencent.mm",
    "appActivity": ".ui.LauncherUI",
    'newCommandTimeout': 6000,
    "noReset": True,
    "unicodeKeyboard": True,
    "resetKeyboard": True,
    "automationName": "uiautomator2",
    "chromeOptions": {"androidProcess": "com.tencent.mm:appbrand0"},
    # "showChromedriverLog": True,
}

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(8)
# 等待activity出现后每两秒查找一次
# driver.wait_activity("",100,interval=2)
# AC = driver.current_activity
# print(AC)

#点击微信
driver.find_elements_by_id('com.tencent.mm:id/dtx')[2].click()
sleep(3)
driver.find_elements_by_id('com.tencent.mm:id/dvz')[6].click()
sleep(3)

driver.find_elements_by_id('com.tencent.mm:id/ik3')[0].click()
sleep(3)

conss = driver.contexts
print('当前小程序所有的上下文:{}'.format(conss))
#切换窗口
print('开始切换上下文')
driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
print('切换成功')

hs = driver.current_window_handle
print('当前所有的窗口为:{}'.format(driver.window_handles))
print('当前所在的窗口为: {}'.format(driver.current_window_handle))
sleep(3)

handles = driver.window_handles
print('所有的窗口句柄:{}'.format(handles))

for handle in handles:
    if handle != hs:
        driver.switch_to.window(handles[-1]) #hs
# for handle in hs:
#     driver.switch_to.window(handle)
#     print('切换到窗口handle:{}'.format(handle))
#     print(driver.page_source)
#     sleep(3)
#     if driver.page_source.find('https://servicewechat.com/preload/page-frame.html') != -1:
#         break
# sleep(3)       
#元素已经被封装,这里直接调用那个模块就行 
for i in range(10):
    new = 1
    ys = driver.find_element(*HomePage.hb).click()
    sleep(4)
    new += i
    print('第:{}次拆红包'.format(new))

# print('当前窗口:{}'.format(driver.current_window_handle))
print('complete')

window_size = driver.get_window_size()
print(window_size)

x = window_size['width']
y = window_size['height']


def swipe_right(driver, t=400, n=1):
    window_size = driver.get_window_size()
    x1 = window_size['width'] * 0.25
    y1 = window_size['height'] * 0.5
    x2 = window_size['width'] * 0.75

    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)


swipe_right(driver)
print('swipe_right')
        

小程序拆红包的一个自动化。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小龚的测试之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值