【问题标题】:Not able to find any element in appium for my mobile app在我的移动应用程序的 appium 中找不到任何元素
【发布时间】:2019-08-12 10:26:01
【问题描述】:

enter image description hereenter image description here我无法在我的移动应用中使用任何使用 appium 的定位器找到元素,请查看随附的屏幕截图和下面的代码

driver.findElementById("serviceUrl").sendKeys("ABC");    
driver.findElementByClassName("android.widget.Button").click();

Appium 服务器响应

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 从客户端获取数据:{"cmd":"action","action":"find","params":{"strategy":"xpath" ,"selector":"//[@class='android.widget.EditText']","context":"","multiple":false}} [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 得到了 ACTION 类型的命令 [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 得到命令动作:find [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 使用 'XPATH' 和 contextId: '' multiple: false [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 定位元素失败。清除辅助功能缓存并重试。 [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 使用 'XPATH' 和 contextId: '' multiple: false [debug] [AndroidBootstrap] 从 bootstrap 收到命令结果 [调试] [MJSONWP] 匹配 JSONWP 错误代码 7 到 NoSuchElementError

【问题讨论】:

  • 你是如何声明和初始化你的驱动的?请在您的原始帖子中显示代码。

标签: selenium appium


【解决方案1】:

而不是这个

driver.findElementById("serviceUrl").sendKeys("ABC"); 

试试这个。

driver.findElementByClassName("android.widget.EditText").sendKeys("ABC");

按照 OP 的建议,您也可以尝试 xapth

driver.findElementByxpath("//*[@resource-id='serviceUrl']").sendKeys("ABC"); 

或者

driver.findElementByxpath("//*[@class='android.widget.EditText']").sendKeys("ABC"); 

【讨论】:

  • 感谢@Kajal 的快速响应,您能否添加 xpath 也使用最好的资源 id 和类名。
  • 如果驱动程序声明正确,第一个版本将工作。如果你想使用 xpath,你必须在 xpath 中指定 resource-id 而不是 "id" 如果你使用正确的驱动,findElementById 将尝试搜索 ID、context-id 和 resource-id (不一定按这个顺序),但 xpath 是不同的。
  • 感谢您的回复,我仍然无法找到具有上述 xpaths 的元素,请查找驱动程序声明 File f= new File("src");文件 fs= 新文件(f,“LS_eCOA.apk”); DesiredCapabilities cap=new DesiredCapabilities(); cap.setCapability(MobileCapabilityType.DEVICE_NAME, "EDC"); cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath()); AndroidDriver driver=new AndroidDriver(new URL("127.0.0.1:4723/wd/hub"),cap);
  • [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] 使用 'XPATH' 和 contextId: '' multiple : false [debug] [AndroidBootstrap] 从 bootstrap [debug] [MJSONWP] 收到的命令结果匹配 JSONWP 错误代码 7 到 NoSuchElementError
【解决方案2】:

你可以试试这个:

driver.findElement(By.id("serviceUrl")).sendKeys("ABC");

【讨论】:

    猜你喜欢
    • 2018-12-19
    • 2018-10-07
    • 2020-12-17
    • 2020-10-01
    • 2018-10-21
    • 2019-09-24
    • 1970-01-01
    • 2023-03-18
    • 2019-12-18
    相关资源
    最近更新 更多