2

My code is :

for (int z = 0; z < rows.size(); z++) {

rows.get(z).findElement(By.xpath("//*[@class='ng-scope'][" + (z + 1) + "]//*[@placeholder='Stop Name']")).sendKeys(shuttleObj.getStopArea());

}

And I want to use repository to pass xpath. I want this value multiple times for every rows in a table but if I am taking properties like

for (int z = 0; z < rows.size(); z++) {

rows.get(z).findElement(By.xpath(props.getProperty("path[" + (z + 1) + "]area")).sendKeys(shuttleObj.getStopArea()));

}

path=//*[@class='ng-scope']
area=//*[@placeholder='Stop Name']

This code is not working. If I am taking total elements like

path=//*[@class='ng-scope'][" + (z + 1) + "]//*[@placeholder='Stop Name']

It can be able to run but in same row. But I want this value in every rows in a table.

5
  • use this - props.getProperty(path+ "[" +(Z+1)+ "]" + value) Commented May 13, 2019 at 4:14
  • sorry my bad just replace value by your area variable name. Commented May 13, 2019 at 9:27
  • i'm not bale to understand that what you want to do, but why are u using " stiil before path variable and after area variable these are your simple variable with string values which you want to use. Commented May 13, 2019 at 10:20
  • why are you not directly using this - props.getProperty(path+ "[" +(Z+1)+ "]" + area) Commented May 13, 2019 at 10:20
  • because path and area are not an elements, these are xpath which i am using in my code like e.g path= //*[@class='ng-scope'] and area=//*[@placeholder='Stop Name'] . I am combining these two xpath and using as one xpath in my code like e.g rows.get(z).findElement(By.xpath("//*[@class='ng-scope'][" + (z + 1) + "]//*[@placeholder='Stop Name']")).sendKeys(shuttleObj.getStopArea()); But I have to use this xpath in below code by using props.getProperty. rows.get(z).findElement(By.xpath(props.getProperty("path[" + (z + 1) + "]area")).sendKeys(shuttleObj.getStopArea()));
    – Samira
    Commented May 13, 2019 at 11:00

1 Answer 1

1

Hope this help you-
Your property file-(db.properties)

path=//*[@class='ng-scope'] 
area=//*[@placeholder='Stop Name']  

Now in your java class-

String pathValue= props.getProperty("path");
String areaValue= props.getProperty("area");

for (int z = 0; z < rows.size(); z++) 
{
rows.get(z).findElement(By.xpath(pathValue+"[" + (z + 1) + "]"+areaValue)).sendKeys(shuttleObj.getStopArea());

}  

Note:- Here if your variable rows is also from properties file then with same above way use this.

3
  • Yes, it's working now. Thank you.
    – Samira
    Commented May 13, 2019 at 11:51
  • Welcome!, please if it's your answer then accept it. Commented May 13, 2019 at 11:59
  • @Samira it's your different question please post it as a new question so that everyone can help you. Commented May 15, 2019 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.