#使用adb mock 方式成功实现小程序自动化,但是在页面跳转之后无法在新的页面获取元素
使用page_source方法将html页面down下来对比,发现是和edge://inspect中的空页面相同
目前问题解决方法应该是在如何同一个webview页面中获取同级页面,请各位大神指教
代码如下:
class TestWxMicro:
def setup(self):
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "d7e9c263"
caps["platformVersion"] = "10.0"
caps["appPackage"] = "com.tencent.mm"
caps["appActivity"] = ".ui.LauncherUI"
caps["noReset"] = 'true'
caps["unicodeKeyboard"] = 'true'
caps["resetKeyboard"] = 'true'
caps["chromedriverExecutable"] = "D:/Chromedriver/wechat_chromedriver/chromedriver_89.0.4389.23.exe" # 微信h5页面chrome启动器
caps["chromeOptions"] = {
"androidProcess": "com.tencent.mm:appbrand0"
}
caps["adbPort"] = 5038
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
self.driver.implicitly_wait(10)
#进入小程序
size = self.driver.get_window_size()
self.driver.swipe(size['width'] * 0.5, size['height'] * 0.4, size['width'] * 0.5, size['height'] * 0.4)
search_icon = self.driver.find_element(By.ID, 'com.tencent.mm:id/f8y')
search_icon.click()
search_text = self.driver.find_element(By.ID, "com.tencent.mm:id/bhn")
search_text.send_keys("雪球")
self.driver.implicitly_wait(10)
wps_app = self.driver.find_element(By.XPATH, '//*[@resource-id="com.tencent.mm:id/tm"]')
wps_app.click()
time.sleep(3)
def teardown(self):
self.driver.quit()
@allure.story("进入个人中心")
def test_user_image(self):
self.driver.switch_to.context("WEBVIEW_com.tencent.mm:appbrand0")
allure.attachment_type.PNG)
page_first = Basepage(self.driver)
try:
page_first.user_image.click()
except:
print("user image click fail")
time.sleep(3)
#切换context之后打印html
#小程序的进程在同一个webview,跳转页面不需要切换context
try:
my_cloud = self.driver.find_element(By.XPATH,"/html/body/wx-user-center/wx-scroll-view/div/div[1]/div/wx-view[4]")
my_cloud.click()
except:
print("find element error")