I want to find element by using a PART of STRING

Hi, guys.

I’m making some Appium scripts with python.

And I need to find some elements that contain part of word,

for example, *.test.*. it can be ABCtest or testDCDC or 123testxcv… anything containing the ‘test’ word.

Is Appium support this function? or Is there any help for me?

I wish that you understand what I mean.

Thank you so much. Good Luck!

Using Android UIAutomator:
find_element_by_android_uiautomator('new UiSelector().textContains("test")')
If you want to use a regular expression, use textMatches instead.

Thank you so much Alexis. I tried it and successed! Thanks a lot!

Would you mind if ask more things?

First, Anything to use self.driver.find_element_by_xpath function?

For example, self.driver.find_element_by_xpath("//android.view.View[@content-desc=’****.text.****’]")

Second, If I use your solution, Is there a way to using both Android and IOS? Is it same to use in ios_uiautomator? Sorry, I cannot test it now in IOS.

I don’t think you can use regular expressions in xpath. It will probably search for exact content.
Unfortunately, UIAutomator methods only work on Android. I am not too familiar with UIAutomation myself, but there might be a similar function. You can use a switch on device name to execute correct code depending on device (I use java, so i can’t give you an accurate example).
There may also be a function in python client that does it on both.

Thanks for kindness. It was great helpful. I’ll check it. Thanks!

Best Regards.