测试人社区

微信小程序找不到webview

wechat_mini.txt (42.5 KB) webview

首先使用命令mitmdump -p 5038 --rawtcp --mode reverse:http://localhost:5037/ -s adb_proxy.py成功开启,然后打开server和设备genymotion andriod 8.0 wechat 7.0.15,然后设置代码如下:
class TestWxMicro:
def setup(self):
desire_caps = {
“platformName”: ‘android’,
“deviceName”: ‘192.168.216.103:5555’,
“appPackage”: ‘com.tencent.mm’,
“appActivity”: ‘com.tencent.mm.ui.LauncherUI’,
“noReset”: ‘true’,
‘unicodeKeyBoard’: ‘true’,
‘resetKeyBoard’: ‘true’,
“ChromedriverExecutable”: “D:/Study/Automation_Tester_Guide/Lesson6_appium/chromedriver”,
“chromeOptions”: {‘androidProcess’: ‘com.tencent.mm:appbrand0’},
“adbPort”: 5038
}
self.driver = webdriver.Remote(“http://127.0.0.1:4723/wd/hub”, desire_caps)
self.driver.implicitly_wait(30)

    self.driver.find_element(By.XPATH,"//*[@text='Contacts']")
    self.driver.implicitly_wait(10)

def teardown(self):
    pass

def test_search(self):
    #原生自动化测试
    size = self.driver.get_window_size()
    width = size.get("width")
    height = size.get("height")
    self.driver.swipe(int(width*0.5),int(height*0.2),int(width*0.5),int(height*0.9),2000)
    self.driver.find_element(By.ID,"com.tencent.mm:id/dt5").click()
    print(self.driver.contexts)

    #进入webview
    self.driver.switch_to.context("WEBVIEW_xweb")
    self.driver.implicitly_wait(10)
    self.find_top_window()


    #css定位/html/body/wx-scroll-view/div/div[1]/div/wx-view/wx-view[3]/wx-navigator/wx-image/div
    self.driver.find_element(By.CSS_SELECTOR,"body > wx-scroll-view > div > div.wx-scroll-view > div > wx-view > wx-view._div.data-v-5667385e.optional__list-none > wx-navigator > wx-image > div").click()
    # self.driver.find_element(By.CSS_SELECTOR,"[src*=stock_add]").click()
    #等待新窗口
    WebDriverWait(self.driver,30).until(lambda x: len(self.driver.window_handles) > 2)
    self.find_top_window()
    self.driver.find_element(By.XPATH,"/html/body/wx-view/wx-view[1]/wx-view/wx-input/div[1]/div[1]").click()
    # # self.driver.find_element(By.CSS_SELECTOR, "._input").click()
    # #输入
    # self.driver.switch_to.context("NATIVE_APP")
    # ActionChains(self.driver).send_keys("alibaba").perform()
    #
    # #点击
    # self.driver.switch_to.context("WEBVIEW_xweb")
    # self.driver.find_element(By.CSS_SELECTOR, ".stock_item")
    # self.driver.find_element(By.CSS_SELECTOR, ".stock_item").click()

def find_top_window(self,driver=None):
    for window in self.driver.window_handles:
        print(window)
        if ":VISIBLE" in self.driver.title:
            print("find")
            print(self.driver.title)
        else:
            self.driver.switch_to.window(window)

微信小程序雪球被打开了,但是webview没有,而且映射看不到visible这种网页,点击空白网页的inspect还能映射打开的雪球