I can find the element but not click it, why?

Dec 6, 2012 at 5:42 PM

Hi all,

I have a heavily scripted UI and am trying to click in the area of an element that I can find but cannot click the control.  The control that I am trying to click is a HighCharts legend element.

Here is the code for the finding the control and returning information about it that verifies that it was indeed found.

This snippit returns the following string.  "<tspan>Actual Count</tspan>"

         // this is how it is called
         var tag = TestedPage.FindTheHighChartsElementByIdInnerText<HtmlDiv>("chtNationalGoals", "Actual Count");
         Console.WriteLine(tag);

         // and this is the definition
        public string FindTheHighChartsElementByIdInnerText<T>(string id, string innerText)
            where T : HtmlControl, new()
        {
            // Find tag to click and then click it
            var elem = Browser.TopParent
                .Find<T>(new { Id = id })   // [@id="chtNationalGoals"]
                .GetChildren()
                .First()                    // [@id="highcharts-nn"]              
                .GetChildren()
                .First()                    // /svg              
                .GetChildren()
                .Where(e => e.GetProperty("class") != null && e.GetProperty("class").ToString() == "highcharts-legend")
                .First()
                .GetChildren()
                .Last()
                .GetChildren()
                .First()
                .GetChildren()
                .First()
                .GetChildren()
                .First()
                .GetChildren()
                .Where(e => e.GetInnerText() == innerText)
                .First();

            var tagName = elem.ClassName.Substring(elem.ClassName.IndexOf('.')+1);
            return string.Format("<{0}>{1}</{2}>", tagName, elem.GetInnerText(), tagName);
        }

And this is the method definition being called with the exact same parameters that is supposed to click the control but instead says that it cannot find it and fails.

        public void ClickTheHighChartsElement<T>(string id, string innerText)
            where T : HtmlControl, new()
        {
            // Find tag to click and then click it
            Point p = Browser.TopParent
                .Find<T>(new { Id = id })   // [@id="chtNationalGoals"]
                .GetChildren()
                .First()                    // [@id="highcharts-nn"]              
                .GetChildren()
                .First()                    // /svg              
                .GetChildren()
                .Where(e => e.GetProperty("class") != null && e.GetProperty("class").ToString() == "highcharts-legend")
                .First()
                .GetChildren()
                .Last()
                .GetChildren()
                .First()
                .GetChildren()
                .First()
                .GetChildren()
                .First()
                .GetChildren()
                .Where(e => e.GetInnerText() == innerText)
                .First()
                .GetClickablePoint();

            Mouse.Click(p);
        }

Dec 6, 2012 at 9:43 PM

More on this...  I did figure out that part of the problem is that I was using the wrong generic type.  I should've been using an HtmlDiv instead of HtmlCustom.  I have since then gotten rid of the generic capability from my method. 

Unfortunately now, no matter how I call this I always get the same error that another control is blocking.  I get that from it (the inner most control), its parent and grandparent when I call there click event.  Incidently, I was told by our JavaScript expert (the one that is writting all this front end code) that the grand parent is the one that should receive the click event.

I have tried this multiple different ways to no avail.

element.Click();

Mouse.Click(element);

Mouse.Click(point);

Nothing works even though you can plainly see the element and click it from the UI, nothing is in the way.  I guess I will try to wait on the control for a bit and see if that helps.