Search code examples
javaandroidseleniumtestingappium

Locator is not working except id on the Appium for Android in WebView


Trying to do the Testing of Android Application coded in WebView. I have an app that I am trying to automate the Test Cases.

I have a login screen having Email and Password which does have id locaters. That is working fine I am able to locate elements. ITs hybrid app made with ionic. The login button does not have id locater.

So far I have tried this thing.

MobileWebBrowserFactory factory;
AndroidDriver<WebElement> appiumdriver;
WebElement LoginElement = appiumdriver.findElement(By.id("username"));
LoginElement.click();
LoginElement.sendKeys("Test");

WebElement PasswordElement = appiumdriver.findElement(By.id("password"));
PasswordElement.click();
PasswordElement.sendKeys("Test");
// Hide Keyboard
appiumdriver.hideKeyboard();
Thread.sleep(2000);

            WebElement LoginButton = appiumdriver
                    .findElementByName("end");

it gave me an exception that name is not allowed locator to find all the times. I have used Android and appium drivers both.

Can anyone Suggest to me good libraries for this? I appreciate your help in advance.

Thanks


Solution

  • I have done certain changes to the code.

    Changed Appium Server to 1.10 to 1.20.2. Used Android Driver Instance.

    Also, Used the Xpath for the non-ionic framework.

    It resolved the issue for me and I am able to locate the element using this.

            WebElement UsernameElement = appiumdriver.findElementByXPath("//*[@id=\"username\"]/input");
            Thread.sleep(1000);
            UsernameElement.click();
            Thread.sleep(1000);
            UsernameElement.sendKeys("mobile3@20212.com");
    

    Maybe the Old Appium was not able to identify the element.