【问题标题】:An element could not be located on the page using the given search parameters (Appium 1.13.0)使用给定的搜索参数(Appium 1.13.0)无法在页面上找到元素
【发布时间】:2020-07-13 20:10:12
【问题描述】:

我正在为 Android 应用程序开发自动化。运行脚本时,Appium 无法找到元素。我尝试使用 Id,Xpath。请帮我解决这个问题...

Android 版本:5.1.1 & 9 Appium 版本:1.13.0 Maven 项目

@Test
public void login() {
    driver.findElement(By.xpath("//com.vehito.vehitoplus[contains(@resource-id,'phone')]")).sendKeys("9632642105");
driver.findElement(By.id("com.vehito.vehitoplus:id/sign_in_button")).click();
}

实际结果: 运行命令遇到内部错误:NoSuchElementError: An element could not be located on the page using the given search parameters

【问题讨论】:

    标签: appium-android testng-dataprovider


    【解决方案1】:

    此错误表示 UIAutomator 无法找到该元素。

    我发现你的 Xpath 代码有 2 个问题:

    1- 在resource-id 之后将, 替换为=。

    2- 您使用 packageName (com.vehito.vehitoplus) 而不是类名。

    您可以使用 UIAutomator Viewer 找到元素的确切类名:

    (Android SDK Dir)\tools\bin\uiautomatorviewer.bat

    我的意思是你可以使用这个:(如果元素的类名是:android.widget.EditText)

            driver.findElement(By.xpath("//android.widget.EditText[contains(@resource-id='phone')]")).sendKeys("9632642105");
    

    根据我的经验,我发现 By. 库(XPath 或 ID)不能很好地与 @contains 配合使用。所以如果你使用确切的属性会更好。

    例如

            driver.findElement(By.id("com.vehito.vehitoplus:id/sign_in_button")).sendKeys("9632642105");
    

    我希望这会有所帮助。如果没有,请提供页面截图以及此输入元素的 UIAutomator 查看器截图。

    【讨论】:

      【解决方案2】:

      org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。 有关此错误的文档,请访问:https://www.seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018-11-14T08:25:53' 驱动信息:io.appium.java_client.android.AndroidDriver 功能 {app: C:\Selenium\workspace\Ninja..., appPackage: com.ninjafocus.app, appactivity: com.ninjafocus.app.base.vie..., databaseEnabled: false, desired: {app: C: \Selenium\workspace\Ninja..., appPackage: com.ninjafocus.app, appactivity: com.ninjafocus.app.base.vie..., deviceName: Nokia 6, newCommandTimeout: 60, platformName: android, platformVersion: 9, udid: PLEGAR1780410318}, deviceApiLevel: 28, 默认套件

          driver.findElementById("\r\n" + "com.ninjafocus.app:id/signinButton").click();
          driver.findElementById("\r\n" + "com.ninjafocus.app:id/parentEmailText").sendKeys("pooja.yadav@gmail.com");
          driver.findElementById("\r\n" + "com.ninjafocus.app:id/parentPasswordText").sendKeys("1234");
          driver.findElementById("\r\n" +"com.ninjafocus.app:id/startedButton").click();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-30
        • 2016-12-26
        • 2017-01-15
        • 2019-06-23
        • 2019-08-30
        • 2021-09-29
        • 1970-01-01
        • 2019-08-18
        相关资源
        最近更新 更多