Forum Discussion

Al2's avatar
Al2
Occasional Contributor
5 years ago
Solved

Unable to click on an object when using GetElementsByClassName

Hi,   I have a small piece of code here as a sampl of what I'm trying to do. But it fails.   function RelVis(){ var page = browser.CH; //this return an array of all the object found with the foll...
  • tristaanogre's avatar
    5 years ago

    What's the contents of that one item in the array?  While it's true that the array may have a single element, it could be that it's a null value or simply an empty element.  The GetElementsByClassName is not a TestComplete method so it's hard to say what it returns.

     

    This is why I suggested FindAllChildren.  What happens if you change your code to

     

    function RelVis(){
    var page = browser.CH;
    //this return an array of all the object found with the following criteria 
    var buttonRel = page.FindAllChildren("className", "btn acute-btn rel", 100);
    
    //Log.Message(buttonRel.length);
    
    if (buttonRel.length > 0) then {
    
        if(buttonRel[0].Exists){
          buttonRel[0].Click();
        }
    }
      }