@costea.georgian89 You have access to the HTML and that is where you can find the various parts of the table that you need to build the program. Now, you had id='leadtable', so you know how to get to view the code.
You should be able to see the structure of the program. We looked for the table and the tbody tags. From there we looked for the row tr tags. Once we had the rows, we then looked for the column td tags. But these I just assumed were there based on your original code. You’re right, something is not adding up.
You now need to look at the HTML and correct, or fine tune, any of the parts of this program that are not correct. As an example, I only assumed there was a “table/tbody” from working with other web tables, but the path structure may be more complicated. You will either have to show the HTML or investigate the web table code further yourself.
1 Like
@grylion54
Here is a screenshot:
@costea.georgian89 I went back to your other question on this and saw that kazurayam had spent the time to get a sample. I have added more to the original code that I amended above, putting in the inner and outer loops again. I also added a delay in the event that the table takes time to fully display.
def ExpectedValue = WebUI.getAttribute(findTestObject('Page_LeadManager - Leads/input_Leads_searchInput'),'value')
WebDriver driver = DriverFactory.getWebDriver()
WebUI.delay(2)
//Expected value from Table
WebElement Table = driver.findElement(By.xpath('id("leadtable")/tbody'));
// To locate rows of table it will Capture all the rows available in the table
List<WebElement> rows_table = Table.findElements(By.tagName('tr'));
boolean found = false;
// To calculate no of rows In table
int rows_count = rows_table.size();
println("rows_count=${rows_count}");
// Loop will execute for all the rows of the table
Loop:
for (int row = 0; row < rows_count; row++) {
def Columns_row = rows_table.get(row).findElements(By.tagName('td'));
int columns_count = Columns_row.size();
println('Number of cells In Row ' + row + ' are ' + columns_count);
'Loop will execute till the last cell of that specific row'
for (int column = 1; column < columns_count; column++) {
'retrieve text from each cell except the first'
celltext = Columns_row.get(column).getText()
println('Cell Value of row number ' + row + ' and column ' + column + ' is ' + celltext)
if (celltext == ExpectedValue) {
found = true;
println('Lead is present ' + Columns_row.get(column).getText());
break Loop;
}
}
}
if (!found) {
KeywordUtil.markFailedAndStop('Lead is not added')
}
1 Like
@grylion54
It works how should work thank you very much!
@grylion54
But I post in a new post. Is not a bug if the Lead is not added is returned like Failed should be highlighted with red? Here is the post:
In else stament if is marked like fail the test step is not highlighted