Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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
我想使用Selenium C#验证3行值的总和是否等于WebTable中的第一行。行是第3行、第6行和;第8行 IList rows=\u driver.FindElements(By.XPath(“//div[@id='data\u 3']]/div/div/div[3]/table/tbody/tr[@class]”); 对于(inti=1;i_C#_Selenium - Fatal编程技术网

我想使用Selenium C#验证3行值的总和是否等于WebTable中的第一行。行是第3行、第6行和;第8行 IList rows=\u driver.FindElements(By.XPath(“//div[@id='data\u 3']]/div/div/div[3]/table/tbody/tr[@class]”); 对于(inti=1;i

我想使用Selenium C#验证3行值的总和是否等于WebTable中的第一行。行是第3行、第6行和;第8行 IList rows=\u driver.FindElements(By.XPath(“//div[@id='data\u 3']]/div/div/div[3]/table/tbody/tr[@class]”); 对于(inti=1;i,c#,selenium,C#,Selenium,,根据我的理解,您需要对三行的值求和,并检查它是否等于第一行的值。我将使用您提供的路径 IList<IWebElement> rows = _driver.FindElements(By.XPath("//div[@id='data_3']/div/div/div[3]/table/tbody/tr[@class]")); for (int i = 1; i <= rows.Count; i++) { IList<IWebElement> columns

,根据我的理解,您需要对三行的值求和,并检查它是否等于第一行的值。我将使用您提供的路径

IList<IWebElement> rows = _driver.FindElements(By.XPath("//div[@id='data_3']/div/div/div[3]/table/tbody/tr[@class]")); 
for (int i = 1; i <= rows.Count; i++)
{
    IList<IWebElement> columns = _driver.FindElements(By.XPath("//div[@id='data_3']/div/div/div[3]/table/tbody/tr[@class][" + i + "]/td[@class]"));

    for (int j = 1; j <= columns.Count; j++)
    {

    }
}
有了它,你可以很容易地检查你想要什么

public int GetRowValue(int rowNumber)
{
    var row = _driver.FindElements(By.XPath("//div[@id='data_3']/div/div/div[3]/table/tbody/tr[@class]"))[rowNumber - 1] // decreased by 1, because if you would like to get first row, it would have 0th index in the array
    var columns = row.FindElements(By.XPath("./td"); // find all tds of the given row.
    int value = 0;
    foreach(var column in columns)
      {
          if (String.IsNullOrEmpty(column.Text)) continue;
          result += Int32.Parse(column.Text);
      }
      return value;
}

那么问题出在哪里呢?有人能告诉我正确的方向吗?我不知道如何继续。发布一个你正在处理的元素的HTML。我只是在寻找逻辑来比较每一列中第3行+第5行+第8行的值等于第1行。我尝试了几种组合,但没有找到它。这是一个简单的WebTable,我使用C#,因为这不起作用我正在进行cucumber场景步骤。我没有创建新方法。我需要知道如何在整个表中应用该公式。您有什么问题?此外,当您提出问题时,您应该在问题中包含“cucumber”标记。GetRowValue(n)因为我没有将int传递到我的方法中,所以不起作用。我基本上只是尝试使用不同的行来添加/比较公式。我需要类似于row1+row2==row1或row3+Row5的内容。我认为,使用我提供给您的代码片段,您应该轻松地根据您的需要对其进行修改。最初的问题没有提到这些新要求。Jonah,我只是用最简单的例子来解释我想做什么。但是我需要找到特定的行值,并在所有列的公式中使用它们。
var row1Value = GetRowValue(1);
var sum = GetRowValue(3);
sum += GetRowValue(6);
sum += GetRowValue(8)
Assert.Equals(row1Value, sum);