Coded UI error: The following element is not longe

2019-02-18 16:33发布

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 no longer available ... and I got the exception : Can't perform "Click" on the hidden control, which is not true because all the controls are not hidden. I tried on the other machine, and they failed as well.

Does anyone know why it happens? Is it because of the web application for something else? Please help, thanks.

PS: So I tried to record a new test with the same controls that said "hidden controls", and the new test worked!? I don't understand why.

EDIT

The warning "The following element blah blah ..." appears when I tried to capture an element or a control while recording. The source code of the button is said 'hidden'

public HtmlImage UIAbmeldenImage
    {
        get
        {
            if ((this.mUIAbmeldenImage == null))
            {
                this.mUIAbmeldenImage = new HtmlImage(this);
                #region Search Criteria
                this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Id] = null;
                this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Name] = null;
                this.mUIAbmeldenImage.SearchProperties[HtmlImage.PropertyNames.Alt] = "abmelden";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.AbsolutePath] = "/webakte-vnext/content/apps/Ordner/images/logOut.png";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Src] = "http://localhost/webakte-vnext/content/apps/Ordner/images/logOut.png";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.LinkAbsolutePath] = "/webakte-vnext/e.consult.9999/webakte/logout/index";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Href] = "http://localhost/webakte-vnext/e.consult.9999/webakte/logout/index";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.Class] = null;
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.ControlDefinition] = "alt=\"abmelden\" src=\"http://localhost/web";
                this.mUIAbmeldenImage.FilterProperties[HtmlImage.PropertyNames.TagInstance] = "1";
                this.mUIAbmeldenImage.WindowTitles.Add("Akte - Test Akte Coded UI VS2010");
                #endregion
            }
            return this.mUIAbmeldenImage;
        }
    }

7条回答
甜甜的少女心
3楼-- · 2019-02-18 17:14

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!

查看更多
三岁会撩人
4楼-- · 2019-02-18 17:20

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.

查看更多
欢心
5楼-- · 2019-02-18 17:22

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

查看更多
冷血范
6楼-- · 2019-02-18 17:23

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

查看更多
趁早两清
7楼-- · 2019-02-18 17:25

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

查看更多
登录 后发表回答