首页 > 解决方案 > PageSource() 获取的代码与 appium 检查器代码不同

问题描述

我很难理解以下问题,我有一个应用程序,我使用 appium 检查器查看元素,但是当我使用元素时,我发现找不到元素,因此我使用驱动程序打印了代码.getPageSource() 方法,我意识到在运行应用程序时创建的 xml 代码实际上与 appium 检查器看到的不同,问题是什么以及如何解决?一旦我知道根本原因,我可以要求开发人员修复它,在此先感谢。

这是一个不同的例子

< XCUIElementTypeOther name = Picture, Left Rear Corner>还有 4 个元素 2 StaticText、2 Buttons (appium inspector) 和同一个元素上,但在 java 控制台中,只有 2 个标签,所以我看不到 2 个静态文本和 2 个按钮(这是什么我想点击)

在此处输入图像描述

在此处输入图像描述

如您所见,控制台中的代码与我在 appium iinspector 中看到的不同。这是针对 IOS 应用程序的。

 while (driver.findElementsById("Additional Videos").size() == 0) {
            swipeScreenDown();
        }
        driver.getPageSource();
        WebElement additionalVideos = driver.findElementByXPath("//XCUIElementTypeOther[@name=\"Picture, Left Front Corner\"]");
        driver.getPageSource();
      List<WebElement> idf = additionalVideos.findElements(By.className("XCUIElementTypeButton"));
        driver.getPageSource();
        System.out.println(idf.size());
        driver.getPageSource();
        idf.get(0).click();
        driver.getPageSource();

错误得到:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

标签: seleniumappiumappium-androidappium-ios

解决方案


PageSource()action 可以在屏幕上打印视觉元素。

据我了解,您当前正在PageSource()加载屏幕时执行操作。

您需要单击所选元素 在此处输入图像描述

单击此元素后,使用PageSource()操作。您会在PageSource().


推荐阅读