Extra space problem while using 'Accessibility id' strategy to locate element in iOS

So I came across this situation where the accessibility id of the element has leading/trailing spaces. To be precise :
Element recorded by appium –

wd.findElement(By.name(“time   “)).click();

or this one :
wd.findElement(By.name(”     duration”)).click();

Is there any way that I can do a contains and not worry about the extra spaces? Something like an @contains feature of xpath?

Thank you.

You could use the -android uiautomator locator strategy, and use descriptionMatches()

Seems we have enough people asking for this, it could be added to the client libraries…

Created an issue: https://github.com/appium/appium/issues/3557

It’s been a feature of the ruby_lib for a while.

1 Like

Well there we go. Maybe we should add it to all the clients…

1 Like

It would be great if the partial match functionality would be implemented for all clients. Hope it’s implemented soon.


 -andoid uiautomator? 
But I am working in iOS. Would that work here?

I see someone writing
it works.
You can find other functions from http://www.w3schools.com/xpath/xpath_functions.asp


Did @Alex_Chen’s suggestion work? @Pratyush

Sounds savvy. I will give it a try and let you know if it works.

@jonahss I haven’t tried it yet. I was kinda busy with the Selenium annual conference. I will test it and let you know the result.

@Alex_Chen I tried searching by xpath with @name as parameter but it did not work. Any other suggestions?

Sometimes you simply need to search by @name=‘XXX’ first, then use that xpath and change @name=‘XXX’ to contains(@name, ‘XXX’), step by step to check whether the xpath works.
When I was trying to do this the first time with “///[contains…]” it crashes appium instrument on server side. Then I finally figure out I have to do this carefully from full reset on simulator and full xpath in Inspector. Before I post, I’m sure it works in circumstances. :stuck_out_tongue: But I’m not sure why it doesn’t work in the other cases.


Woah! That’s insane. I will give it a shot – step by step :smiley: Hopefully things will work.

The only way I write tests is by using a repl like the ruby appium_console or the javascript AppiumRepl. I build up all the locators step by step.


I have been building the locators all at once. Guess I’ve been doing it wrong. Building step by step has its advantage. I will do that. Thank you.

It worked like a charm. Thank you @Alex_Chen


What @Alex_Chen suggested works perfectly :slight_smile: