从动态表中行文本

时间:2013-05-30 01:05:22

标签: extjs selenium webdriver selenium-webdriver

我对Selenium Webdriver很新,所以请原谅我使用的所有'noob'术语。

我在页面上有一个动态表格,表格中有4列。除此之外,只能编辑第一列名称。该表如下所示:

(sorry, stack overflow wont let me post images)

现在使用Webdriver,我需要找到'group102'并验证与'group102'对应的Level和Card的数量(基本上是两列其余部分的文本)。这里要注意的关键点是这个群体本质上是动态的。现在,它坐在第3排,但明天可能在第1排或第10排。

我正在使用Visual Studio(C#)和Selenium webdriver。 请让我知道如何进步

编辑: HTML代码:

<div id="formbland-1013" class="x-panel x-panel-default x-form-bland x-form-base" style="height: 9588px;">
 <div id="formbland-1013-body" class="x-panel-body x-panel-body-default x-panel-body-default" style="left: 0px; top: 0px; width: 680px; height: 9588px;">
  <span id="formbland-1013-outerCt" style="display: table; width: 100%; table-layout: fixed;">
   <div id="formbland-1013-innerCt" style="display:table-cell;height:100%;vertical-align:top;">
    <div id="ext-comp-1026" class="x-panel x-panel-default x-form-bland x-form-base" style="width: 680px; height: 47px;">
     <div id="ext-comp-1036" class="x-panel x-panel-default x-form-bland x-form-base" style="width: 680px; height: 9541px;">
      <div id="ext-comp-1036-body" class="x-panel-body x-panel-body-default x-panel-body-default" style="left: 0px; top: 0px; width: 680px; height: 9541px;">
       <span id="ext-comp-1036-outerCt" style="display: table; width: 100%; table-layout: fixed;">
        <div id="ext-comp-1036-innerCt" style="display:table-cell;height:100%;vertical-align:top;">

我正在尝试的代码:

ReadOnlyCollection<IWebElement> select = WebDriver.FindElements(By.XPath("//td[contains(text(),'group102')]"));
if ("group102e".Equals(select.ToString()))
{
    throw new SystemException("Group matches according to the Access");
}
else
{
    throw new SystemException("Group does not matches according to the Access");
}

1 个答案:

答案 0 :(得分:1)

我无法提供确切的代码,因为我不知道该表的HTML。但这是理论上的代码。

首先通过文本获得IWebElement输入,然后转到祖先td的兄弟姐妹(即此行中的下两个列单元格),然后获取元素的文本。

IWebElement inputGroup = WebDriver.FindElement(By.CssSelector("tbody input[value='group101']"));
IWebElement level = inputGroup.FindElement(By.XPath("(.//ancestor::td/following-sibling::td)[1]"));
string levelA = level.Text;

我对您的代码的疑问:

  1. "group102e".Equals(select.ToString())没有意义,因为您的selectReadOnlyCollection<IWebElement>,这是IWebElements的列表,ToString不会给您任何有用的信息

  2. var location = WebDriver.FindElement(By.CssSelector("tbody input[value='Practice Wide Group 2']")).Location.ToString();,你想要什么?元素的位置(类型为System.Drawing.Point)?