Search code examples
c#coded-ui-testsweb-testing

Coded UI - Clicking on a hyperlink in a table cell which is Dynamically generated


My test Condition is to Click on a hyperlink in a cell. --> Table format Tr, Td

Table Columns Name -- Status -- link

--> 1st we search the row to match the name .

--> After row is found with our search we check the status in the 2nd column, same row.

--> the status changes from processing to Complete.

--> When the Status is Complete a Hyperlink is generated in the 3rd column. Which needs to be clicked.

Upon checking the source code through F12. the Link is generated as a child element of the cell in the 3rd column. So im trying to find row.cell(2).GetChildren[0];

But as the child element is existing only when the Link is generated, which depends on the application Loading.

i can keep playback.wait(); but that condition is not to be used in my organization until unless its dead end.

Im giving Search properties and waitfor control exist. But that also doesnt work.

Can anyone guide how to wait for the Link which is not existing in the UI currently.

my code looks like below.

HtmlRow row = FindReport(reportName); // Method which finds row
VerifyStatus(reportName, status); // Method verifies status in the row and 
returns true if complete
HtmlSpan link = new HtmlSpan(row);
link.SearchProperties.Add(HtmlSpan.PropertyNames.InnerText, "Order", 
PropertyExpressionOperator.Contains);
for (int i = 0; i < 60; i++)
{
  if (!link.WaitForControlExist())
  {
   Keyboard.SendKeys(HistoryPage, "{F5}");
  }
else
  {
   Mouse.Click(row.Cells[2].GetChildren()[0]);
   return;
  }
}

Im stuck here.


Solution

  • Maybe you need to use some kind of custom waitforcontrolexist, with your own steps for researching the control and your own specific timeout.

    I'm working on desktop software projects, so not html project, but I guess it should work the same way.

    Here is a part of code I use in a more generic function, readapted for your case, if it could help:

    HtmlRow row = FindReport(reportName); // Method which finds row
    VerifyStatus(reportName, status); // Method verifies status in the row and returns true if complete
    HtmlSpan link = new HtmlSpan(row);
    
    int TimoutMilliSecond = 120000//as you told about 2 minutes for the link to be accessible
    int count = 1;
    bool ControlExist = false;
    
    while (ControlExist == false)
    {
            link.SearchProperties.Add(HtmlSpan.PropertyNames.InnerText, "Order", PropertyExpressionOperator.Contains);
    
            if (link != null)//null or in your case any bad state you get as result after the SearchProperties on 'link'
            {
                ControlExist = link.Exists;
            }
    
            if (count > TimoutMilliSecond)
            {
                Assert.Fail("The control 'link' was not found within the timout set out to: " + TimoutMilliSecond.ToString() + " Milliseconds !");
            }
            Playback.Wait(100);
            count = count + 100;
    }
    if (link != null)
    {
        link.Find();
    }