Varin
Varin

Reputation: 119

Coded UI - custom property

I am working on a Coded UI project with code first approach, and I ran into a situation where an element that I am interested in does not have an "ID" property, but "data-id" property instead.

How would I be able to fire up Mouse.Click() on the "Original" link in the example below:

<div class="not-unique" data-uid="93fdb678-2d04-4543-b129-e146453704e6">
    <div class="editor-row">
        <div>
            <ul>            
                <li><a id="dwnOriginal_247" href="">Original</a></li>
                <li><a id="dwnOriginal_247" href="">Error</a></li>
            </ul>
        </div>
    </div>
</div>

Upvotes: 1

Views: 202

Answers (1)

Ryan Cox
Ryan Cox

Reputation: 958

You can use a custom property if you set your locator like this:

public HtmlHyperlink originalLink()
{
    HtmlHyperlink target = new HtmlHyperlink(browser);
    target.SearchProperties["customId"] = "dwnOriginal_247";
    // and then find the Original link using InnerText
    target.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Original");
    return target;
}

Then, you can simply call back to originalLink() for your click:

mouse.Click(originalLink());

Upvotes: 1

Related Questions