Al2
5 years agoOccasional Contributor
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 following criteria var buttonRel = page.contentDocument.getElementsByClassName("btn acute-btn rel"); //Log.Message(buttonRel.length); if(buttonRel[0].Exists){ buttonRel[0].Click(); } }
Just FYI, the lenght of this array is 1. I've checked it a few times while debugging it.
But what i get is this. I'd really appreciate it anyone can point out the problem here.
Thank you
Al2
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(); } } }