Xpath Byname Byid

Hi,

the below code was running fine in Aappium 1.4.16.1 version after uograding to 1.6.3 its not working

I already knew that By.name is no more supported in the latest version, so i modified the code with xpath still unable to run it successfully

the part of code will verify the elements based on it “Name” and “ID”, then it pass one by one in the for loop and verify weather it is present, if yes increment the count and it will say that particular element is present or not

now i am unable to verify the elements based on the element id as well as the name.

Can anyone help on this

driver.findElementByXPath("//android.widget.TextView[@text=‘Login with your test ID’]").click();
Thread.sleep(2000);
getScreenshot(“Main_without_login”);
int count = 0;
//To verify the following elements are present in the login page
String[] myArr = {“test IDs”, “Usage without logging in”, “com.test.mobile.android.mytest:id/body_icon”, “Log in with your test ID”, “Log in with your test ID to access the full features.”, “com.test.mobile.android.mytelstra:id/auth_info_button”};

	          for(int i =0; i<myArr.length; i++){
	          	try{
	          		if(myArr[i].contains("com.test")){
	          			MobileElement e = driver.findElement(By.id(myArr[i]));
	          			System.out.println(e);
	          			count++;
	          		}
	          		else{
	          			MobileElement e = driver.findElement(By.name(myArr[i]));
	          			//MobileElement e = driver.findElementByXPath("//android.widget.TextView[@text=(myArr[i])]");
	          			System.out.println(e);
	          			count++;
	          		}
	          	}

	catch (NoSuchElementException e){
	          	
	          		System.out.println(myArr[i] + " not found");
	          		Reporter.log("Screen Element" + " " + myArr[i] + " " + "not found");
	          		getScreenshot("Failed Screenshot/_Skip_Login_MobEle_myLogin Not Found");
	               }
	  	  
	        }

try:

((AndroidDriver) driver).findElementByXPath("//android.widget.TextView[@text='Login with your test ID']").click();
//or better
driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\""+ your_text_variable + "\")")));

Hi i want to know how to pass the array element value by name(wont work)/by xpath to my code

I want to know how to pass my array value to the loop

able to pas the array value using By.id but using Xpath how??

Hi Cepin

I was really glad that Xpath was useful, so i easy converted Byname to ByXpath

but again i have strucked up

i need to pass a set of string values to array

one by one text i need to validate whether that element is available in my device or not

Initially my code was working with Byname now as i have to use double quotes for Xpath my Array value getting converted into normal texts

so what syntax i can use

code snippet:

int count = 0;
//To verify the following elements are present in the login page
String[] myArr = {“test IDs”, “Usage without logging in”, “com.test.mobile.android.mytest:id/body_icon”, “com.test.mobile.android.mytelstra:id/auth_info_button”};

for(int i =0; i<myArr.length; i++){
try{
if(myArr[i].contains(“com.test”)){
MobileElement e = driver.findElement(By.id(myArr[i]));
System.out.println(e);
count++;
}
else{
// MobileElement e = driver.findElement(By.name(myArr[i])); //old syntax how to give the xpath
MobileElement e = driver.findElementByXPath("//android.widget.TextView[@text=’(myArr[i])’]"); //not working wont work resolution needed for this line of code
System.out.println(e);
count++;
}
}

catch (NoSuchElementException e){
	System.out.println(myArr[i] + " not found");
	Reporter.log("Screen Element" + " " + myArr[i] + " " + "not found");
	getScreenshot("Failed Screenshot/_Skip_Login_MobEle_myLogin Not Found");
}

the output i am getting is “test IDs not found”