如何从appium中的资源ID获取视图对象?

时间:2016-04-07 11:20:31

标签: android appium android-bitmap

我正在使用appium进行测试自动化。我需要将view对象存储到当前应用程序屏幕的位图中。

public Bitmap takeScreenShot(View view) {
    view.setDrawingCacheEnabled(true);
    view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
    view.buildDrawingCache();

    if(view.getDrawingCache() == null) return null;

    Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
    view.setDrawingCacheEnabled(false);
    view.destroyDrawingCache();

    return snapshot;
}

AppiumDriver driver = new AndroidDriver(new URL(""),capabilities);//capabilities and URL are set
WebElement el = driver.findElement(By.id("com.example.app:id/video_view"));

View view = ?? //get view object from el
takeScreenShot(view);

1 个答案:

答案 0 :(得分:0)

试试这个,它应该返回类似android.widget.RelativeLayout 的东西(只是一个例子):

View view = el.getAttribute("className"); //get class value of the element