Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 830
Kishan Bheemajiyani Avatar asked May 17 '21 15:05

Kishan Bheemajiyani


Video Answer


2 Answers

I didn't work with Appium for a long time, so maybe I'm wrong, but as I remember, Appium supports locating elements by id or xpath only.
So, instead of findElementByName try findElementByXpath.
The locator should be changed accordingly, so it will be something like

WebElement LoginButton = appiumdriver.findElementByXpath("//*[@name='end']");
like image 51
Prophet Avatar answered Oct 16 '22 06:10

Prophet


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("[email protected]");

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

like image 33
Kishan Bheemajiyani Avatar answered Oct 16 '22 07:10

Kishan Bheemajiyani