How to read list of all controls and its value that contains specific text?

Apr 19, 2013 at 3:34 PM
Edited Apr 19, 2013 at 3:35 PM
Hi,

I would like to read all the values of a specific control whose property using regular expression.

Example: Say, there are 'n' controls of hyperlink controltype, and the innertext has a specific name convention.

Now I want to read all the "DisplayText" of the hyperlinks whose InnerText starts with "A", how can this be achieved?

CUITe_HtmlHyperlink("InnerText=A - B - C");
CUITe_HtmlHyperlink("InnerText=A - F - E");
CUITe_HtmlHyperlink("InnerText=A - D - E");
CUITe_HtmlHyperlink("InnerText=Z - B - C");
CUITe_HtmlHyperlink("InnerText=Z - D - E");

Thanks in advance!


Regards,
Rohit
Coordinator
Apr 22, 2013 at 1:34 AM
Edited Apr 22, 2013 at 1:34 AM
Hi Rohit,

This can be achieved by using the GetChildren() method on the parent control.

Here is some sample code:
using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"">
            <a href=""#"">A - B - C</a>
            <a href=""#"">A - F - E</a>
            <a href=""#"">A - D - E</a>
            <a href=""#"">Z - B - C</a>
            <a href=""#"">Z - D - E</a>
        </div>
    </body>
</html>"))
            {
                CUITe_BrowserWindow.Launch(tempFile.FilePath);
                CUITe_BrowserWindow window = new CUITe_BrowserWindow("test");

                List<ICUITe_ControlBase> collection = window.Get<CUITe_HtmlDiv>("id=div1").GetChildren();
                foreach (ICUITe_ControlBase control in collection)
                {
                    if (control is CUITe_HtmlHyperlink)
                    {
                        CUITe_HtmlHyperlink link = (CUITe_HtmlHyperlink)control;
                        if (link.InnerText.StartsWith("A"))
                        {
                            Trace.WriteLine(string.Format("found: {0}", link.InnerText));
                        }
                    }
                }

                window.Close();
            }
Apr 24, 2013 at 2:09 PM
Edited Apr 24, 2013 at 2:09 PM
Thank you for your response.

When I use this, I get only the first matching control and not all. Any thought around this?

List<ICUITe_ControlBase> collection = oLoginPage.Get<CUITe_HtmlHyperlink>("InnerText~Adam").GetChildren();
        foreach (ICUITe_ControlBase control in collection)
        {
            if (control is CUITe_HtmlHyperlink)
            {
                CUITe_HtmlHyperlink link = (CUITe_HtmlHyperlink)control;
                if (link.InnerText.Contains("Adam"))
                {
                    MessageBox.Show(link.InnerText.ToString());
                    //Trace.WriteLine(string.Format("found: {0}", link.InnerText));
                }
            }
        }
Coordinator
Apr 25, 2013 at 5:22 AM
Try this:
List<ICUITe_ControlBase> collection = oLoginPage.GetChildren();

        foreach (ICUITe_ControlBase control in collection)
        {
            if (control is CUITe_HtmlHyperlink)
            {
                CUITe_HtmlHyperlink link = (CUITe_HtmlHyperlink)control;
                if (link.InnerText.Contains("Adam"))
                {
                    MessageBox.Show(link.InnerText.ToString());
                    //Trace.WriteLine(string.Format("found: {0}", link.InnerText));
                }
            }
        }