FindElement by a part of is name

Hello,

I would like to know if it is possible to try to find a element by a part of is name ?
For exemple, il I know the name of the button is begining like “user:…”, can I try to find it with the world user?

Hi,

You can use xpath contains() method:

xpath=//*[contains(text(), 'user')] // Case sensitive

OR

xpath=//*[contains(@text, 'user')] // Case sensitive

thanks a lot, is it possible to make also something like:

xpath=//*[!contains(@text, ‘user’)] // Case sensitive

to find an element WITHOUT something inside?

Edit: I found it:

xpath=//*[not(contains(@text, ‘user’))] // Case sensitive

1 Like

Just a last question about xpath, how I can make a condition on child?
something like
IOSElement Element = driver.findElement(By.xpath("//*[ @XCElementType= 'XCUIElementTypeCell' and /descendant::* = not(contains(@text, 'user'))] ]"));