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.
jonahss
September 3, 2014, 6:21pm
2
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
jonahss
September 3, 2014, 6:24pm
4
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.
@jonahss
-andoid uiautomator? But I am working in iOS. Would that work here?
I see someone writing
UIATableCell[contains(@name ,‘Settings’)]
it works.
You can find other functions from http://www.w3schools.com/xpath/xpath_functions.asp
2 Likes
jonahss
September 5, 2014, 11:11pm
8
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. But I’m not sure why it doesn’t work in the other cases.
2 Likes
Woah! That’s insane. I will give it a shot – step by step Hopefully things will work.
jonahss
September 11, 2014, 10:36pm
14
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.
2 Likes
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
2 Likes
What @Alex_Chen suggested works perfectly