I'm a bit out of my depth, but I'll do my best to explain. I'll put my question up top and then my explanation below:
"How do I tell Selenium to only read the results that are visible on the browser, and not what is held in the page source?"
I have a web page for which I've been creating automated tests using Selenium WebDriver. On the page there is a table of results, usually about 50 or so. When the user hits the page, all results are displayed. If they enter text into a search box, they can filter the results down. Nothing fancy. My goal is to ensure that the number of results returned by the table match the expected number.
The code that I've been using to count the number of results is this:
public int searchTableNumberOfMatchesOneColumn(String tableIdParam, int columnToSearchParam, String valueToFindParam){
int numberOfMatchesFound = 0;
WebElement table_element = driver.findElement(By.id(tableIdParam));
List<WebElement> tr_collection=table_element.findElements(By.xpath("id('" + tableIdParam + "')/tbody/tr"));
int row_num = 1;
int col_num = 1;
for(WebElement trElement : tr_collection)
{
List<WebElement> td_collection=trElement.findElements(By.xpath("td"));
col_num=1;
for(WebElement tdElement : td_collection)
{
if(col_num == columnToSearchParam && tdElement.getText().equals(valueToFindParam)){
numberOfMatchesFound++;
}
col_num++;
}
row_num++;
}
return numberOfMatchesFound;
}
The problem that I'm running into is this: This code always returns the FULL size of the table, 50 or so, and not the number of results visible on screen. I opened up the page source for the web page before and after searching to do a comparison, and they're identical. So while what is visible to the user changes, what is stored in the page source is not.
I've tried using a JavascriptExecutor to look for innerHTML, but it returns the same results. (As does doing driver.findElement(By.tagName("body")).getText();
Any help is appreciated.