Hi, I am seeing the below error on my xpath.
Error: “driver.findElement(By.xpath(”//div[@id=‘a0O3F0000048iUk_00N30000003tWTk_body’]/table/tbody"))
Elapsed time: 22.977s
Table = driver.findElement(By.xpath(“//div[@id=‘a0O3F0000048iUk_00N30000003tWTk_body’]/table/tbody”)) FAILED.
Reason:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“xpath”,“selector”:“//div[@id=‘a0O3F0000048iUk_00N30000003tWTk_body’]/table/tbody”}"
Code:
WebDriver driver = DriverFactory.getWebDriver()
//‘Expected value from Table’
String ExpectedValue = “Facets ASO Medical”;
//‘To locate table’
WebElement Table = driver.findElement(By.xpath(“//div[@id=‘a0O3F0000048iUk_00N30000003tWTk_body’]/table/tbody”))
//‘To locate rows of table it will Capture all the rows available in the table’
List rows_table = Table.findElements(By.tagName(‘tr’))
//‘To calculate no of rows In table’
int rows_count = rows_table.size()
//‘Loop will execute for all the rows of the table’
for (int row = 0; row < rows_count; row++) {
//‘To locate columns(cells) of that specific row’
List Columns_row = rows_table.get(row).findElements(By.tagName(‘td’))
//‘To calculate no of columns(cells) In that specific row’
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 = 0; column < columns_count; column++) {
//‘It will retrieve text from each cell’
String celltext = Columns_row.get(column).getText()
println((((('Cell Value Of row number ’ + row) + ’ and column number ') + column) + ’ Is ') + celltext)
//‘Checking if Cell text is matching with the expected value’
if (celltext == ExpectedValue) {
//‘Getting the Group Product Record Name if cell text i.e GP Record Type matches with Expected value’
println('Text present in row number 3 is: ’ + Columns_row.get(2).getText())
}
}
}