求助【微信小程序】混合型,图中弹框是 原生的,怎么定位上面的“确定”按钮?

xpath不就搞定了 //*[@text=‘确定’]

老师,这种试过没法定位到,
有“确定”按钮的弹框是 NATIVE_APP,后面的页面是WEBVIEW_com,如果是两种中的一种就可以定位到,如果两种同时出现不行,也试过 driver.switch_to.context 方法

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: Timed out after 15525ms waiting for the root AccessibilityNodeInfo in the active window. Make sure the active window is not constantly hogging the main UI thread (e.g. the application is being idle long enough), so the accessibility manager could do its work

贴下你的代码,同时打印下当时的page source,你当时是在哪个上下文?

from time import sleep
from appium import webdriver
from selenium.webdriver.common.by import By

desired_cap={
“platformName”:‘Android’,
“recreateChromeDriverSessions”:True,
“deviceName”:‘51db8c2’,
“appPackage”:‘com.tencent.mm’,
“appActivity”:‘com.tencent.mm.ui.LauncherUI’,
“unicodeKeyboard”: True,
“resetKeyboard”:True,
‘automationName’: ‘appium’,
“noReset”:True,
“newCommandTimeout”:4000,
“chromedriverExecutable”:r"C:\UI_auto\tool\chromedriver_89.exe",
“browserName”:None,
# ‘chromeOptions’: {‘androidProcess’ : ‘com.tencent.mm:appbrand0’}
}

driver = webdriver.Remote(‘http://127.0.0.1:4730/wd/hub’,desired_cap)
print(driver.current_context)
sleep(3)

driver.swipe(540,684,527,2000)
driver.find_element(By.XPATH,"//*[contains(@text,‘体验版’)]").click()
sleep(3)
print(driver.current_context)
sleep(10)

contexts=driver.contexts
print(contexts)
print(driver.current_context)

sleep(2)
print(driver.current_context)
print(len(contexts))

for i in range(len(contexts)):
driver.switch_to.context(contexts[i])
try:
driver.find_element(By.XPATH,"//[contains(@text,‘wetest白名单检测’)]/ancestor::/[@resource-id=‘com.tencent.mm:id/lk’]//[@text=‘确定’]").click()
print(driver.current_context)
except:
print("**************************")
print(driver.current_context)
print(“未找到元素”)
if driver.current_context!=‘NATIVE_APP’:
print(driver.page_source)

打印日志.txt (920.5 KB)

关闭