uiautomatorviewer和appium无法捕获App页面
报错
uiautomatorviewer报错
Error obtaining ui hierarchy Reason:error taking device screenshot:EOF
appium报错
App Source Could not obtain source: [object Object]
appium server日志报错
Error: Cannot get screenshot data because of 'The size of the taken screenshot equals to zero.'. Make sure the 'LayoutParams.FLAG_SECURE' is not set for the current view
原因
App页面已经被禁止截屏,禁用用户截屏的代码如下:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);setContentView(R.layout.activity_main);
解决
执行代码,进入该页面,通过String source = driver.getPageSource();
获取该页面的dom,通过dom找到需要定位的元素。