从动态表中行文本

时间:2022-10-30 19:24:27

I am pretty new to Selenium Webdriver, so pardon me for all d 'noob' terminology used.

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

I have a dynamic table on the page, with 4 columns in the table. Out of this, only the first column name can be edited. The table looks like this :

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

从动态表中行文本

Now using Webdriver, I need to locate 'group102' and verify the Level and the number of Cards (basically the text of the rest of the two columns) corresponding to 'group102'. The key point to note here is that this group is dynamic in nature. Right now, its sitting in row 3 but tomorrow, it may be on row 1 or row 10.

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

I am using Visual Studio (C#) and Selenium webdriver. Please let me know how can I progress

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

EDIT : HTML CODE:

编辑: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;">

CODE WHICH I AM TRYING :

我正在尝试的代码:

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 个解决方案

#1


1  

I can't provide exact code as I don't know the HTML for the table. But here are the code in theory.

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

You get the IWebElement input first by text first, then go to ancestor td's siblings (i.e. the next two column cells in this row), then get the element's text.

首先通过文本获取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;

My questions about your code:

我对你的代码的疑问:

  1. "group102e".Equals(select.ToString()) doesn't make sense, since your select is ReadOnlyCollection<IWebElement>, which is a list of IWebElements, ToString won't get you anything useful?

    “group102e”.Equals(select.ToString())没有意义,因为你的select是ReadOnlyCollection ,这是一个IWebElements列表,ToString不会给你带来什么有用的东西?

  2. var location = WebDriver.FindElement(By.CssSelector("tbody input[value='Practice Wide Group 2']")).Location.ToString();, what do you want here? The location of the element (which is in the type of System.Drawing.Point)?

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

#1


1  

I can't provide exact code as I don't know the HTML for the table. But here are the code in theory.

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

You get the IWebElement input first by text first, then go to ancestor td's siblings (i.e. the next two column cells in this row), then get the element's text.

首先通过文本获取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;

My questions about your code:

我对你的代码的疑问:

  1. "group102e".Equals(select.ToString()) doesn't make sense, since your select is ReadOnlyCollection<IWebElement>, which is a list of IWebElements, ToString won't get you anything useful?

    “group102e”.Equals(select.ToString())没有意义,因为你的select是ReadOnlyCollection ,这是一个IWebElements列表,ToString不会给你带来什么有用的东西?

  2. var location = WebDriver.FindElement(By.CssSelector("tbody input[value='Practice Wide Group 2']")).Location.ToString();, what do you want here? The location of the element (which is in the type of System.Drawing.Point)?

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