1

For example "//XCUIElementTypeStaticText[@text='Accept All']" which name 'Accept All' can be changed base on the language, for example, Spanish will change to 'Aceptar todas'

example :

<android.widget.TextView index="0" package="com.android.chrome" class="android.widget.TextView" text="Aceptar todas" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[412,1386][669,1438]" displayed="true" />

In this case how to make sure this XPath works with this condition?

2 Answers2

0

You can pass the language string as parameter.
You didn't mention what language you are using, so I will use Java here, but this can be done with any other language similarly.
Let's say we are passing the language as language string parameter.

String xpathTemplate = "//XCUIElementTypeStaticText[text()='%s']";
String xpath = String.format(xpathTemplate,language);
driver.findElement(By.xpath(xpath));
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Thanks for the info, really helpful. The issue here is that the language quite random and the value also not under control. –  Jun 23 '21 at 13:48
  • depends the language the phone is using , something it returns text="Aceptar todas" as above example shows as spainish and sometime shows in english text="Accept All" etc. The approach for you its great , but it will have to manually set the language value instead of programmatically detect –  Jun 23 '21 at 13:49
  • So, you mean the `name` attribute value is dynamically changing? In this case you should base your locator on something else, that is not being changed without your control – Prophet Jun 23 '21 at 13:53
  • yep , this is the page source and is the only way to detect that element. the pity things is that the text field value is dynamically changing, I can "//XCUIElementTypeStaticText[@name='Accept All']" it works in english , but in spainish it will fail –  Jun 23 '21 at 13:56
  • 1
    BTW... there is no name attribute on that element. You all are referring to `text`. – JeffC Jun 23 '21 at 13:57
  • yes , sorry, its text , apology and I updated the question –  Jun 23 '21 at 14:04
  • Possibly you can uniquely identify that element on dependence of some unique parent element – Prophet Jun 23 '21 at 14:04
0

Can you try something like

//android.widget.TextView[@index='0'] or //android.widget.TextView[0]

here is reference : Xpath for Android element using Appium

N..
  • 906
  • 7
  • 23