0

I have a test case with below mentioned code:

[TestMethod]
public void _001_Search()
{
    BrowserWindow brw = BrowserWindow.FromProcess(proc_browserProcessNo);
    TopLeftNavigationLinks_Elements.ClickLink1TopNavigationLink(brw);
}

It uses two non-test methods:

Method1:

namespace Links
{
    public class TopLeftNavigationLinks_Elements
    {
        public static void ClickLink1TopNavigationLink(BrowserWindow brw)
        {
            //Find the Link1 top nvaigation menu link and click it
            var elementName_ToBeLocated = LocateUIElementByIdentifiers.GetElementLocators_FromUiElementsSheet(str_sheetName, "ele_Link1");
            GenericFunctions_ForLocatingElements.FindHyperLink_Click(brw, elementName_ToBeLocated.Item1.ToString());
            logger.Info("Link1 was found and clicked");
        }
    }
}

Method2:

namespace Functions
{
    public class GenericFunctions_ForLocatingElements
    {
        public static HtmlHyperlink FindHyperLink_Click(BrowserWindow brw, string str_uiElementPrimaryLocator)
        {
            XmlConfigurator.Configure();
            Boolean bol_hyperLinkFound;
            HtmlHyperlink html_hyperLink = new HtmlHyperlink(brw);
            //Verify if the browser window exists or not
            if (brw.Exists)
            {
                html_hyperLink.SearchProperties.Clear(); //Clear the existing Search Logic
                Console.WriteLine("1");
                //Find the HyperLink with the InnerText verify if it exists or not
                html_hyperLink.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, str_uiElementPrimaryLocator, PropertyExpressionOperator.Contains);
                Mouse.Click(html_hyperLink);
                Console.WriteLine(str_uiElementPrimaryLocator);
                bol_hyperLinkFound = html_hyperLink.Exists;
                Console.WriteLine(bol_hyperLinkFound.ToString());
                //Verify if the HyperLink exists or not with the specified Search logic
                if (bol_hyperLinkFound)
                {
                    logger.Info(html_hyperLink.ToString() + " found by InnerText");
                    if (html_hyperLink.Enabled) //Verify if the HyperLink is enabled or not
                    {
                        Mouse.Click(html_hyperLink); //Click the HyperLink
                        Console.WriteLine("3");
                        logger.Info(html_hyperLink.ToString() + " is clicked");
                    }
                    else
                    {
                        logger.Info(html_hyperLink.ToString() + " can't be clicked because it is not enabled");
                        Assert.IsTrue(html_hyperLink.Enabled, "HyperLink with InnerText " + str_uiElementPrimaryLocator + " is not enabled");
                    }
                }
                else
                {
                    //Display this message if HyperLink not found by InnerText
                    logger.Info("HyperLink with InnerText " + str_uiElementPrimaryLocator + " not found");
                    Assert.IsTrue(bol_hyperLinkFound, "Hyperlink with InnerText " + str_uiElementPrimaryLocator + " not found on the " + brw + " window.");
                }
            }
            else
            {
                Assert.IsTrue(brw.Exists, "Browser window for finding the Hyperlink with InnertText " + str_uiElementPrimaryLocator + " does not exist");
            }
            return html_hyperLink;
        }
    }
}

Now the issue is, Coded Ui is not Clicking the HyperLink, it is able to find the same but not clicking the link. While if I use the following code in Method1 and doesn't use Method2, Mouse Pointer is moved to that link and it is able to click the same.

namespace Links
{
    public class TopLeftNavigationLinks_Elements
    {
        public static void ClickLink1TopNavigationLink(BrowserWindow brw)
        {
            //Find the Link1 top nvaigation menu link and click it
            var elementName_ToBeLocated = LocateUIElementByIdentifiers.GetElementLocators_FromUiElementsSheet(str_sheetName, "ele_Link1");
            HtmlHyperlink h = new HtmlHyperlink(brw);
            Console.WriteLine(elementName_ToBeLocated.Item1);
            h.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, elementName_ToBeLocated.Item1, PropertyExpressionOperator.Contains);
            Mouse.Click(h);
            logger.Info("Link1 was found and clicked");
        }
    }
}

Why Coded UI is not able to Find and Click the element using Method1 and Method2 both.

1

I got the solution for the above issue, the code line html_hyperLink.SearchProperties.Clear(); was causing problem, after removing this line test cases are working fine as required.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.