Xpath inspect 2 elements at once

109 views
Skip to first unread message

Dave

unread,
Jan 25, 2023, 11:04:49 PM1/25/23
to Automate
Hello.

I've been trying to use Interact block with

".//android.widget.TextView[@android:text='mytext1'] and .//android.widget.TextView[@android:text='mytext2'] 

But it doesn't work. I tried "++", same. It can ask text1 or text2 with "|" as separator, but can it inspect 2 elements at the same time, and go YES if both are here, and NO if 1 or 0 are here ?

Thanks

Henrik "The Developer" Lindqvist

unread,
Jan 26, 2023, 8:22:32 AM1/26/23
to Automate
The Interact block only operate on a single UI element, i.e. the first match, but the Inspect layout block can match/return multiple nodes:


So your example would be:

.//android.widget.TextView[@android:text='mytext1'] | .//android.widget.TextView[@android:text='mytext2'] 

but since both is of the same element, also:

.//android.widget.TextView[@android:text='mytext1' or @android:text='mytext2'] 

Dave

unread,
Jan 26, 2023, 11:12:06 PM1/26/23
to Automate
You answered about "X or Y"

But is it possible to do "X and Y" 

If possible that it inspects 2 elements and say if they are both present at the same time. For example a TextView1 and a TextView2, or a TextView and an ImageView ?

I know that "or" and "|" work for 1 or 2 
But I can't make 1 + 2  works. The "and" doesn't work and return "Can not convert #Boolean to a Nodelist"

Thanks!

Henrik "The Developer" Lindqvist

unread,
Jan 27, 2023, 8:25:50 AM1/27/23
to Automate
My examples will not result in either X or Y, but both, i.e. all matching nodes, will be returned.

Do you mean only return X and Y if both exist/match?

In the Inspect layout block ensure to use Node-set as the Result type.

Dave

unread,
Jan 29, 2023, 11:41:17 AM1/29/23
to Automate
What I meant was to go the YES path if both X and Y are on the screen, and go NO path if only 1 of them (or 0) are on the UI layout.

What works but needs 2 blocks is :

Inspect Layout (result UI_layout) and then If True block : 
1 = contains(UI_layout, "X") && 1 = contains(UI_layout, "Y")

It works in that case, but I wanted to make this in only 1 block.

Henrik "The Developer" Lindqvist

unread,
Jan 30, 2023, 10:09:18 AM1/30/23
to Automate
In that case i guess this should work, with Rsult type set to Boolean:
.//android.widget.TextView[@android:text='mytext1'] and .//android.widget.TextView[@android:text='mytext2']

Reply all
Reply to author
Forward
0 new messages