简体   繁体   English

从行中获取元素(Telerik Test Studio)

[英]Get elements from row (Telerik Test Studio)

So I need to get all the values from a bunch of rows using Telerik Test Studio. 因此,我需要使用Telerik Test Studio从一堆行中获取所有值。 I basically recorded a test to go to a certain page on a web app, and I have a row called Session ID with a few randomly generated rows below it and I want to get the values from those rows, to use with code or whatever. 我基本上记录了一个测试,以转到Web应用程序上的某个页面,并且我有一个名为“会话ID”的行,其下面有一些随机生成的行,我想从这些行中获取值,以与代码或其他任何方式一起使用。 How would I go about doing it? 我将如何去做? Here is a picture of what I mean: 这是我的意思的图片:

http://imgur.com/ol4XRuH

This can be achieved in a coded step . 这可以通过编码步骤来实现。

Let's say you have a few rows in a html table and you want to get their values. 假设您在html表中有几行,并且想要获取它们的值。 You need to collect all rows in a collection and then just take the value of each member of the collection. 您需要收集集合中的所有行,然后仅获取集合中每个成员的值。

Here is an example: 这是一个例子:

HTML: HTML:

<table id="table">
    <tr>
        <td>1</td>
    </tr>
    <tr>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
    </tr>
    <tr>
        <td>5</td>
    </tr>
    <tr>
        <td>6</td>
    </tr>
</table>

The code of the coded step in C#: C#中编码步骤的代码:

HtmlTable myTable = ActiveBrowser.Find.ById<HtmlTable>("table"); //Locate the table
IList<HtmlTableRow> myList = myTable.Find.AllByTagName<HtmlTableRow>("tr");//Collect all rows.
foreach (HtmlTableRow rows in myList)
    {
    Log.WriteLine(rows.InnerText.ToString());
    }

Here is a video demonstration. 这是一个视频演示。

Hope I could help. 希望我能帮上忙。

You can find the ID or any other attribute in the HTML structure of the application (eg in Chrome/IE by pressing F12). 您可以在应用程序的HTML结构中找到ID或任何其他属性(例如,在Chrome / IE中,按F12键)。

Here is a sample code against Telerik ASP gridview page . 这是针对Telerik ASP gridview页面的示例代码。 Here I am retrieving the first row and then only the first column: 在这里,我检索第一行,然后检索第一列:

HtmlTable myTable = ActiveBrowser.Find.ById<HtmlTable>("ctl00_ContentPlaceHolder1_RadGrid1_ctl00");
IList<HtmlTableRow> myList = myTable.Find.AllByTagName<HtmlTableRow>("tr");
//First row
Log.WriteLine(myList[11].InnerText.ToString()); 
//First column
for (int i = 11; i < myList.Count; i++)
    {
    Log.WriteLine(myList[i].Cells[1].InnerText.ToString());
    }

I also recorded another video for a demonstration. 我还录制了另一个视频进行演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM