appium之webdriver与webview
结构图
webdriver协议与⼿⼯模拟
1 2 3 4 5 6 7 8
| # session_id获取 session_id=`curl http://127.0.0.1:4723/wd/hub/sessions | awk -F\" '{print $8}' ` # element id获取 curl -X POST http://127.0.0.1:4723/wd/hub/session/$session_id/elements --data-binary'{"using":"xpath","value":"//*[@class=\"android.widget.Toast\"]"}' -H "Content-Type:application/json;charset=UTF-8" # 元素属性获取 curl http://127.0.0.1:4723/wd/hub/session/$session_id/element/$element_id/attribute/text # 元素动作 curl -X POST http://127.0.0.1:4723/wd/hub/session/$session_id/element/$element_id/click
|
webview
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md
1 2 3 4 5 6 7 8 9 10
| getContextHandles 查看所有的webview进程 adb shell cat /proc/net/unix | grep webview context切换 把domain socket映射为本地的socket端口 adb forward tcp:$port localabstract:webview_devtools_remote_$pid 获取对应的webview组件版本http://localhost:$port/json/version chromedriver协议交互 微信小程序调试开关 debugx5.qq.com
|
等待
1 2 3 4 5
| driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
|
调试分析
1 2 3
| Appium Log 清晰记录了所有的请求和结果 getPageSource 界⾯的完整dom结构. xml⽂件 driver.findElementsByXPath(“//*") #利⽤xpath获取所有匹配的元素(脚本内调试)
|
questions
chrome的inspect弹出空白
1.手机数据线连接电脑,开启手机上的USB调试功能
2.微信访问debugx5.qq.com,点击信息打开TBS内核inspector调试和X5jscore inspector调试
3.打开Chrome浏览器,在地址栏输入:chrome://inspect/#devices访问
4.开始页面会一直空白
原因:国内无法访问 https://chrome-devtools-frontend.appspot.com,chrometophone.appspot.com
解决:代理