Forum Discussion
5 Replies
UPD: AlexKaras beat me to it. :)
If there are no other objects with IDs ending in "MenuInner", you can use wildcard search:
var mainMenu = page.FindChild("idStr", "*MenuInner", 10);
Since v. 11.2, Find methods also support regular expressions:
var mainMenu = page.FindChild("idStr", "regexp:^(main)|(nav)MenuInner$", 10);
A couple of notes:
- Use FindChild and not Find. Find starts searching from the parent object itself (in your example - page), FindChild skips the parent object.
- The fourth parameter of Find/FindChild is a boolean (Refresh=true/false) and not a number. Review the parameters to make sure they are correct.
- AlexKaras
Champion Level 3
Hi Dave,
Two more options:
a) Wildcards: e.g. var mainMenu = page.Find("idStr", "*MenuInner", 10, 1000);
b) Regular expressions: e.g. var mainMenu = page.Find("idStr", "regexp: (mainMenuInner)|(navMenuInner)", 10, 1000);
- roydRegular Contributor
Hi Alex
Thanks for a very clever solution (at least simple enough for me to understand it!). :) I will definitely give it a try and let you know (I don't see why it won't work).
I never thought about using wild card, brilliant! Fortunately, there is only one instance MenuInner. Now I have three different solutions to the my problem, love it!! Also thanks for clarifying Find and FindChild issue, I will correct that.
Thanks to you both! :D
- shankar_rCommunity Hero
Hi,
If i was in that situation, i will do like below:
var mainMenu = page.Find("idStr", "mainMenuInner", 10, 1000); var navMenu = page.Find("idStr","navMenuInner", 10, 1000); var menuObject = null; if(mainMenu.Exists) { menuObject = mainMenu; Log.Message("selected the object with idStr as mainMenuIner"); } else if(navMenu.Exists) { menuObject = navMenu) Log.Message("selected the object with idStr as navMenuInner"); } //Here use if to check whether that has object or not if(menuObject != null) { //Do your stuff }
- roydRegular Contributor
Thank you Shankar, I'll give it a try and let you know how it goes.
Good to see you.
Dave