Forum Discussion

sean_ng's avatar
sean_ng
Occasional Contributor
6 years ago
Solved

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,...
  • sean_ng's avatar
    sean_ng
    6 years ago

    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.");
        }
     }