How to Handling multiple web/mobile elements using xpath?

Unable to capture mobile elements in one xpath.

Hello, please add a further description of your problem.

if a form has multiple inputtext field like --> android.widget.edittext

my script for one input field is given below,
Mobile.tap(findTestObject(‘MobileLoginObejcts/android.widget.FrameLayout0’),0)
Mobile.setText(findTestObject(‘MobileLoginObejcts/android.widget.EditText0’),“task description”, 0)

if we have mulitple input fields then how to capture those multiple input field in a unique manner or how to write a single xpath which holds all input field of that particular form.

image

So you want to capture all inputs by single xpath, right? Can I ask you what the reason is?

the reason is , i can put them in as list and provide values into the input fields using code below,

Mobile.setText(findTestObject(‘MobileLoginObejcts/android.widget.EditText0’).getActiveXpaths().get(1),“test”,0)

otherwise i need to find unique xpath or objects fora each input field, which is not working.
Which is putting the texts in one field oly , since all input fields have same object name called android.widget.edittext

A better approach would be to define a parameterized xpath that you can populate with the appropriate attribute to find the field you want. For example, maybe all of the fields in your screenshot are <input> elements with a unique id attribute, like this:

<input type="text" id="id1"></id>
<input type="text" id="id2"></id>

etc.

Then you could write an xpath like this:

//input[@id='${id}']

and call each of them from your script like this:

Mobile.setText(findTestObject(‘path/to/test/object’, ['id' : 'id1']),“test”,0)
Mobile.setText(findTestObject(‘path/to/test/object’, ['id' : 'id2']),“test”,0)

etc.

But without seeing the HTML for those fields, I can’t provide you a concrete solution.

this is mobile automation, there is no html and all, it will be having android objects.

1 Like

I have the same trouble

can anyone please provide solution to this. Due to this i started hating KS

1 Like

I’m not sure if we have the same problem encountered. What I did was I used the Xpath as the Selected Locator for each object.

:slight_smile:

if we have mulitple input fields then how to capture those multiple input field in a unique manner or how to write a single xpath which holds all input field of that particular form.

You must use unique identifiers to narrow your selection down to the subset of fields that you want.