【发布时间】:2018-11-08 00:40:36
【问题描述】:
我正在为一个应用程序(iOS 和 android appium 版本 1.7.0)开发翻译自动化。这意味着我应该浏览应用程序的所有页面,然后我使用 gcloud api 来识别语言。
我需要帮助找到一种有效的方法来收集特定屏幕上显示的所有文本。
目前我正在使用这个方法,如下面的代码:
- 我找到页面上的所有元素
-
我得到了带有 Text 属性的那些
public void displayText() { System.out.println("i will display all the text and each of their languages"); // I find all the elements on the page as such List<MobileElement> list = driver.findElements(By.xpath("//*")); assertTrue(list.size()>0) ; System.out.println(list.size()); //foreach of the elements detected I determine the language for(int i=0;i<list.size();i++) { if (list.get(i).getText()!= null) { String SeenText = list.get(i).getText(); System.out.println(SeenText); //Lang detection List<Detection> detections =translate.detect(ImmutableList.of(list.get(0).getText())); System.out.println("Language(s) detected:"); for (Detection detection : detections) { System.out.printf("\t%s\n", detection);} }} System.out.println(driver1.getPageSource());
但这仅适用于元素很少的页面。内容繁重的分页需要很长时间,以至于 appium 会话超时。
我考虑过手动解析“driver.getPageSource())”的结果,但我不确定这是否可靠。
有什么更好更实用的方法来获取屏幕上的所有文本的想法吗?
谢谢!
【问题讨论】: