將微信的網(wǎng)頁用inspect獲取元素

1.在聊天窗口輸入:
http://debugx5.qq.com
2.安裝tbs
3.點擊信息,打開tbs內核inspector調試功能

Paste_Image.png

4.在網(wǎng)頁打開inspect,獲取到需要的元素

Paste_Image.png
Paste_Image.png

問題:
微信的webview可以定位元素了,但是用appium的context還是不能轉換成功,是不是因為webview沒有開啟debug的原因?這個只能用來調試頁面了

環(huán)境:
真機中Android system webview版本55.0.2883.91
appium中chromedriver 版本2.25與上面55對應
chromedriver路徑:
D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win
5.應用中webview需要在代碼中設置打開debug:
WebView.setWebContentsDebuggingEnabled(true);
才會inspect成功

Paste_Image.png

Paste_Image.png
Paste_Image.png

最后找到了元素,運行成功
問題:
不是每次都能夠完全的成功轉換,有時候會獲取到undefined,這個就不能轉換,怎么提高可靠性?

代碼:

import os,time
from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'avd2'
# desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appPackage'] = 'com.example.administrator.myapplication'
# desired_caps['appActivity'] = '.ui.LauncherUI'
desired_caps['appActivity'] = '.MainActivity'
desired_caps['automationName'] = 'appium'
desired_caps['newCommandTimeout'] = '300000'
desired_caps['autoWebview'] = 'true'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)
for con in cons:
    if 'WEBVIEW' in con and 'undefine' not in con:
        result=driver.switch_to.context(con)
        break
cur=driver.current_context
driver.find_element_by_xpath("http://*[@id=\"kw\"]").send_keys('hello')
driver.switch_to.context("NATIVE_APP")
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容