Is there a way to GetElementContainingTextInName

There are few dynamic elements created with a time stamp.Eg: “2:30PM MyElementName” Is there a way to search for such element. GetElementByName works only if there is an exact element name match. Is there something like GetElementContainingTextInName?

1 Like

Can you add tags to your post? (edit the title). We need to know what language, appium version, and platform you are testing.

use predicates on iOS or uiselectors on Android. They both support nameContains searching.

I tried below code and it din seem to help
self.driver.find_element_by_ios_uiautomation(“elements().withPredicate("mytext.isVisible == TRUE")”)

The xpath of the element that I am trying to find is //UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[3]/UIAStaticText[1] (Note the name and value of this element is “2:30PM mytext”
In this case how do i put together the search string for find_element_by_ios_uiautomation?

That’s because the predicate is wrong. Have you read the docs about ios predicates?

http://appium.io/slate/en/master/?ruby#ios-predicate

1 Like

@bootstraponline thanks for the pointers!

I got below code working with appium version 1.1.0

text=“random text"
self.driver.find_element_by_ios_uiautomation(“tableViews()[0].cells().withPredicate(“name CONTAINS '”+ text +”’")”)
However, i upgraded to appium 1.2.2 and this method is not able to find the element anymore.

try this, notice the dot

text=“random text"
self.driver.find_element_by_ios_uiautomation(".tableViews()[0].cells().withPredicate(“name CONTAINS '”+ text +"’")”)

using a dot helped! .tableViews()
Thanks

@bootstraponline I am trying to find an element by value instead of name and i used

self.driver.find_element_by_ios_uiautomation(".tableViews()[0].cells()[0].textFields().withPredicate(“value CONTAINS ‘1-222’”)")
This does not seem to work. Any suggestions?

XPath of the element is UIATableView[1]/UIATableCell[1]/UIATextField[1]

you can try contains[c] instead of CONTAINS. Apple has a guide on predicates.
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Predicates/predicates.html

1 Like