-2

There is a web page http://sfs.gov.ua After I type "лист"(its ukrainian) in the search field and press submit button I receive a text message wich says "5536 results have been found in total" and a table which displays how many matches have been found in a certain chapter (the first column is CHAPTER, the second is QUANTITY) screenshot

My task is to sum up all quantities from the result table and compare it with a total value. I understand, that the quantity of rows in a table is dynamic as it depends on search-strings so I can not know how much rows will there be and I should in some way loop over these rows in order to retrieve the quantity values and to sum them. Please explain me how I could do that, I am newbie in SeleniumWebDriver and I would be grateful for examples.

2 Answers2

0

You can get total from the text, got from element located using.search__info css locator. How to extract number from text you can find here.

To get "Кіль-сть" you can use .table_search tbody tr td:nth-child(3) css selector, that will return third column element from all rows.

Here is simple example of code:

// Find search info element and get text
string searchInfo = driver.FindElement(By.CssSelector(".search__info")).Text;

// Extract number from text and convert to integer
int total = Int32.Parse(Regex.Match(searchInfo, @"\d+").Value);    

List<WebElement> rows = driver.FindElements(By.CssSelector("a"));
int rowsTotal = 0;
foreach (IWebElement row in rows)
{
    rowsTotal += Int32.Parse(row.Text);
}

// Assert values here as example
Assert.AreEqual(total, rowsTotal);
Sers
  • 12,047
  • 2
  • 12
  • 31
0

I'm not sure what do you want to check, because in your example 719 + 1282 is not equal to 5536. But there is an example how to do it:

String textWithTotalCount = driver.FindElement(By.Class("search__info")).Text;
Int totalCount = Int32.Parse(Regex.Match(textWithTotalCount, @"\d+").Value);

IList<IWebElement> rows = driver.FindElements(By.Xpath("table[@class='table table_search']/tbody/tr"));
IList<int> countList = rows.ConvertAll(x => Int32.Parse(x.findElement(By.Xpath("/td[-1]")).getText())).ToList();

Assert.Equal(totalCount, countList.Count());
Alex Chumakin
  • 56
  • 1
  • 5