locked
A html hyperlink is not actually exist but it can enter into 'true' part if. RRS feed

  • Question

  • Hi,

    A hyper link is not actually available in our web page. But coded UI always can enter into true part if condition e.g.,if (hyperlink.Exists).

    So I tried with the option 'EnsureClickable()'. This returns the following exception.

    The control is not visible. Additional Details: 

    TechnologyName:  'Web'
    ControlType:  'Hyperlink'
    Id:  ''
    Name:  ''
    TagName:  'A'

    This issue not only with hyperlink but also html buttons too.

    So please let me know how to make the CodedUI to enter into else block of the above mentioned condition.

    Thanks in advance.


    Thanks & Regards, Sasisekar J

    Monday, August 6, 2012 1:34 PM

Answers

  • Hi Sasisekar,

    Perhaps I have misunderstood, but it sounds like you have a hyperlink that is dynamically shown or hidden on a webpage.  However, because the link is always there (even though it is not visible) your .Exists statement is always returning true.  You need a way to determine whether or not the link is visible on the screen and therefore enabled for the currently logged in user.  Have you tried .TryGetClickablePoint()?  Perhaps the below will help:

                // Assuming you've already defined the HtmlHyperlink as link
                System.Drawing.Point point = new Point();
                if (link.TryGetClickablePoint(out point) != false)
                {
                    // Click on your hyperlink here, it's visible and available.
                }
                else
                {
                    // The UI Test could not find a clickable (i.e. visible) point, and so has returned false
                    // Do something here when the link is not visible.
                }

    Hope this helps,

    David

    Thursday, August 9, 2012 11:52 AM

All replies

  • Hi Sasisekar J,

    Every time I have ran into this issue, I have found that the control in question has at least one property that has a different value depending on the state of the control. The one that I always try to go by is Html.ControlDefinition, if it is available. This filter property will have one value when the control is actually visible on the page, and a different value when the control is not visible.

    There might be other properties as well, but this one always works for me, and it is easy to find. All you need to do is start the Coded UI Test Builder, and drag the cross hairs over the control in question when it is visible. This will show you all the control specific property values along with the other properties. See what the value of the ControlDefinition property is and use that as your condition for the if/else statement. If the value is not what you just copied, then go to the else clause. 

    Hope this helps,

    Nat


    Monday, August 6, 2012 2:26 PM
  • Thanks NatRam for this quick reply.

    In our this will be dynamic link. For example if I create a record for a person then there will be a link in a dynamic grid with person's name.

    So in this case the ControlDefinition property is not reliable or it is not fixed one.

    And if you have any sample code please share.

    Once again thanks for reply.


    Thanks & Regards, Sasisekar J

    Monday, August 6, 2012 2:41 PM
  • Have you tried going by PropertyNames.DisplayText instead?

    An example of the one I suggested earlier would be  

      if (uISpWarningPane.ControlDefinition.Contains("style=\"DISPLAY: block\" id=spWarning class=\" warning\""))
                        {
                           do something;
                        }

    else

       { do something else;}

    If this property doesn't work, there must some other property you can use that is always present. (You have to identify the control somehow). Is it possible for you to create a couple of records and then look at the links for both, and see what do they have in common? Then look for that property when the links are not visible and see what the value is then. Even if it's null, you now have something to compare it against. 

    Another one you could use is HtmlControl.InnerText. If the link's inner text is supposed to be the name of the person you just created a record for, then maybe you could use that? You could use HtmlButton.DisplayText for html buttons

    if(HtmlHyperlink.InnerText.Equals("Person's Name"))

    {...}

    else

    {...}

    Nat 




    Monday, August 6, 2012 3:21 PM
  • Yes NatRam.

    We have tried that.

    But in the mentioned case we dont know in advance about the person name.

    Time being we find the grid where the person name may appear and iterate through the grid for any available hyperlinks.

    And click on that link.

    If we know the person name in advance we can use the DisplayText property. But here in our case we cant use it.

    And more over if you look into the exception that I posted above it says 'The control is not visible'.

    So we tried to search such kind of property (visible) but nothing is available.

    The usefulness of the property 'Exist' is really questionable here.


    Thanks & Regards, Sasisekar J

    Tuesday, August 7, 2012 5:05 AM
  • Hi Sasisekar,

    Thank you for posting in the MSDN forum.

    If you add the assertion with Coded UI test Builder on that control, what result did you get? Could you share us a screen shot about it? Could you use the Mouse.Click(Your Control)? If it worked well, maybe you could try to use the WaitForControlExists there on this control. See “How To: Make playback wait for certain event?

    Reference:

    Control is not visible

    Troubleshooting Record and Playback issues in Coded UI Test

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 8, 2012 5:11 AM
    Moderator
  • Hi Sasisekar,

    Perhaps I have misunderstood, but it sounds like you have a hyperlink that is dynamically shown or hidden on a webpage.  However, because the link is always there (even though it is not visible) your .Exists statement is always returning true.  You need a way to determine whether or not the link is visible on the screen and therefore enabled for the currently logged in user.  Have you tried .TryGetClickablePoint()?  Perhaps the below will help:

                // Assuming you've already defined the HtmlHyperlink as link
                System.Drawing.Point point = new Point();
                if (link.TryGetClickablePoint(out point) != false)
                {
                    // Click on your hyperlink here, it's visible and available.
                }
                else
                {
                    // The UI Test could not find a clickable (i.e. visible) point, and so has returned false
                    // Do something here when the link is not visible.
                }

    Hope this helps,

    David

    Thursday, August 9, 2012 11:52 AM