search object with dynamic id using find Child By X Path
hi, i am using ChildByXPath function to look for object on web but i am having problem because the id is dynamic.
id = ABC-60 the value 60 will keep changing on every click.
what i want to do is, find the object using only ABC- and leave the value behind blank and when test complete search for the object it will search for every object that contain ABC-
so regardless of what value is after ABC- test complete will be able to click on it.
How can i do that ? Below is my code :
var obj= ChildByXPath("//*[@id=\"ABC-60\"]"); function ChildByXPath(xpath) { var page = Sys.Browser("Chrome").Page("*"); var obj = page.FindChildByXPath(xpath, true); if (obj != null) { return obj; } else { Log.Error("The element was not found."); } }
Hi AlexKaras,
Thank you for your reply.
i was having trouble using findchild function, i know and understand that you advice me to avoid using xPath but i found one code that is working for my case. I'll try my best to avoid xPath for test complete in future.
Below, i would like to share the code that i am using ..
var obj = ChildByXPath("//*[starts-with(@id, 'ABC-')]"); function ChildByXPath(xpath) { var page = Sys.Browser("Chrome").Page("*"); var obj = page.FindChildByXPath(xpath, true); if (obj != null) { return obj; } else { Log.Error("The element was not found."); } }