Coded UI error: The following element is not longer availabe

后端 未结 7 849
清歌不尽
清歌不尽 2021-01-14 15:44

I recorded some test cases with CUIT in VS2010. Everything worked fine the day before. So, today I run again, all the test failed, with the warning: The following element is

相关标签:
7条回答
  • 2021-01-14 16:21

    One of the biggest problem while analyzing the Coded UI test failures is that the error stack trace indicates the line of code which might be completely unrelated to the actual cause of failure.

    I would suggest you to enable HTML logging in your tests - this will display step by step details of how Coded UI tried to execute the tests - with screenshots of your application. It will also highlight the control in red which Coded UI is trying to search/operate upon.This is very beneficial in troubleshooting the actual cause of test failures.

    To enable tracing you can just add the below code to your app.config file --

    0 讨论(0)
  • 2021-01-14 16:22

    Although I am running Visual Studio 2012, I find it odd that we started experiencing the same problem on the same day, I can not see any difference in the DOM for the Coded UI Tests I have for my web page, but for some reason VS is saying the control is hidden and specifies the correct ID of the element it is looking for (I verified that the ID is still the same one). I even tried to re-record the action, because I assumed that something must have changed, but I get the same error.

    Since this sounds like the same problem, occurring at the same time I am thinking this might be related to some automatic update? That's my best guess at the moment, I am going to look into it, I will update my post if I figure anything out.

    EDIT

    I removed update KB2870699, which removes some voulnerability in IE, this fixed the problems I was having with my tests. This update was added on the 12. september, so it fits. Hope this helps you. :)

    https://connect.microsoft.com/VisualStudio/feedback/details/800953/security-update-kb2870699-for-ie-breaks-existing-coded-ui-tests#tabs

    0 讨论(0)
  • 2021-01-14 16:27

    There may be a field in the SearchProperties (or possible the FilterProperties) that has a value set by the web site, or that represents some kind of window ID on your desktop. Another possibility is that the web page title changes from day to day or visit to visit. Different executions of the browser or different visits to the web page(s) create different values. Removing these values from the SearchProperties (or FilterProperties) or changing the check for the title from an equals to a contains for a constant part of the title should fix the problem. Coded UI often searches for more values than the minimum set needed.

    Compare the search properties etc for the same control in the two recorded tests.

    Update based extra detail given in the comments:

    I solved a similar problem as follows. I copied property code similar to that shown in your question into a method that called FindMatchingControls. I checked how many controls were returned, in my case up to 3. I examined various properties of the controls found, by writing lots of text to a debug file. In my case I found that the Left and Top properties were negative for the unwanted, ie hidden, controls.

    For your code rather than just using the UIAbmeldenImage property, you might call the method below. Change an expression such as

    HtmlImage im = UIMap.abc.def.UIAbmeldenImage;
    

    to be

    HtmlImage im = FindHtmlHyperLink(UIMap.abc.def);
    

    Where the method is:

    public HtmlImage FindHtmlHyperLink(HtmlDocument doc)
    {
        HtmlImage myImage = new HtmlImage(doc);
        myImage.SearchProperties[HtmlImage.PropertyNames.Id] = null;
        myImage.SearchProperties[HtmlImage.PropertyNames.Name] = null;
        myImage.SearchProperties[HtmlImage.PropertyNames.Alt] = "abmelden";
        myImage.FilterProperties[HtmlImage.PropertyNames.AbsolutePath] = "/webakte-vnext/content/apps/Ordner/images/logOut.png";
        myImage.FilterProperties[HtmlImage.PropertyNames.Src] = "http://localhost/webakte-vnext/content/apps/Ordner/images/logOut.png";
        myImage.FilterProperties[HtmlImage.PropertyNames.LinkAbsolutePath] = "/webakte-vnext/e.consult.9999/webakte/logout/index";
        myImage.FilterProperties[HtmlImage.PropertyNames.Href] = "http://localhost/webakte-vnext/e.consult.9999/webakte/logout/index";
        myImage.FilterProperties[HtmlImage.PropertyNames.Class] = null;
        myImage.FilterProperties[HtmlImage.PropertyNames.ControlDefinition] = "alt=\"abmelden\" src=\"http://localhost/web";
        myImage.FilterProperties[HtmlImage.PropertyNames.TagInstance] = "1";
        myImage.WindowTitles.Add("Akte - Test Akte Coded UI VS2010");
    
        UITestControlCollection controls = myImage.FindMatchingControls();
    
    
        if (controls.Count > 1)
        {
            foreach (UITestControl con in controls)
            {
                if ( con.Left < 0 || con.Top < 0 )
                {
                    // Not on display, ignore it.
                }
                else
                {
                    // Select this one and break out of the loop.
                    myImage = con as HtmlImage;
                    break;
                }
            }
        }
    
        return myImage;
    }
    

    Note that the above code has not been compiled or tested, it should be taken as ideas not as the final code.

    0 讨论(0)
  • 2021-01-14 16:30

    Shut down VS2010, launch it again "Run as administrator".

    0 讨论(0)
  • 2021-01-14 16:32

    The problem is more serious than that! In my case I can't even record new Coded UI Tests. After I click in any Hyper Link of any web page of my application the coded UI test builder cannot record that click "The following element is no longer available....".

    Apparently removing the updates, as said by AdrianHHH do the trick!

    0 讨论(0)
  • 2021-01-14 16:36

    I had the same problem on VS 2012. As a workaround, you can remove that step, and re-record it again. That usually works.

    0 讨论(0)
提交回复
热议问题