Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式搜索codedui uimap_C#_Visual Studio_Coded Ui Tests - Fatal编程技术网

C# 以编程方式搜索codedui uimap

C# 以编程方式搜索codedui uimap,c#,visual-studio,coded-ui-tests,C#,Visual Studio,Coded Ui Tests,我有一个对象在codedui uimap中。。。假设是 UIMap.Browser.Document.Table.Row.Cell 例如,您的代码如下所示: UITestControl testcontrol = this.UIMap.Browser.Document.Table.Row.Cell; 我需要找到对象“Cell”作为完全限定名,给定字符串“Browser.Document.Table.Row.Cell” 结果必须是UITestControl,以便测试可以对其进行操作 其思想是,

我有一个对象在codedui uimap中。。。假设是

UIMap.Browser.Document.Table.Row.Cell
例如,您的代码如下所示:

UITestControl testcontrol = this.UIMap.Browser.Document.Table.Row.Cell;
我需要找到对象“Cell”作为完全限定名,给定字符串“Browser.Document.Table.Row.Cell”

结果必须是UITestControl,以便测试可以对其进行操作

其思想是,使用包含路径的字符串,在uimap中查找实际对象

我可以生成包含对象“路径”的字符串,只是不知道如何在uimap中搜索它,并将其链接回UITestControl

(这都是从C#的角度出发的)

e、 g


在这种情况下,
nameofFunctionWeeed
接受字符串,并输出UITestControl对象。

这可能会解决您的问题:

UITestControl nameoffunctionweneed(string path)
{
    object res = UIMap;
    foreach (var item in path.Split('.'))
    {
        res = res.GetType().GetProperty(item).GetValue(res, null);
    }
    return res as UITestControl;
}

这可能会解决您的问题:

UITestControl nameoffunctionweneed(string path)
{
    object res = UIMap;
    foreach (var item in path.Split('.'))
    {
        res = res.GetType().GetProperty(item).GetValue(res, null);
    }
    return res as UITestControl;
}

最好直接使用元素,因为路径可能经常更改。因此,您最好使用简单的CodedUI方法来搜索元素

给定:

<html>
<body>
 <table>
   <tr>
       <td id="x1_y1"><span>hello World!</span></td>
   </tr>
 </table>
</body>
</html>

最好直接使用元素,因为路径可能经常更改。因此,您最好使用简单的CodedUI方法来搜索元素

给定:

<html>
<body>
 <table>
   <tr>
       <td id="x1_y1"><span>hello World!</span></td>
   </tr>
 </table>
</body>
</html>

完美-做它需要做的事情!完美-做它需要做的事情!