Search code examples
seleniumxpathappiumxcuitest

XPATH text set dynamic value base on the language


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?


Solution

  • 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));