Appium获取通知栏内容、捕获toast

一、获取通知栏内容

1)获取通知栏内容 [JAVA]

  • 获取的是appium捕获的通知数据
Map<String, Object> res = (Map<String, Object>)driver.executeScript("mobile: getNotifications");
System.out.println(res);
return JSONObject.toJSONString(res);

2)打开通知栏 [JAVA]

AndroidDriver driver = (AndroidDriver) device.getDriver();
driver.openNotifications();

3)点击通知消息 [JAVA]

driver.findElementByAndroidUIAutomator("new UiSelector().text(\"MobPush\")").click();
  • 也可以使用xpath获取App通知:MobileBy/xpath://android.widget.TextView[@text='url推送测试']        备注:test是推送内容
  • 也可以使用MobileBy/AndroidUIAutomator
    • python里的捕获通知元素方法使用 [Python]:
  • driver.open_notifications() push_res = driver.find_element_by_android_uiautomator('new UiSelector().text("%s")'%(content)) push_res.click()
  • find_element_by_android_uiautomator = find_element_by_name(这个和appium版本有关)

 二、捕获toast [Java]

String toast = driver.findElementByXPath("//*[@class='android.widget.Toast']").getText();
print(toast);
return toast;

 

posted @ 2020-12-03 15:58  拂晓lu  阅读(687)  评论(0编辑  收藏  举报