I get an error when my script is unable to find a web table. When the table is present, it finds it and gives me the right results. Please see the following code and suggest what I need to change:
This is what I have in the Keywords:
class FavoritesKeywords {
@Keyword
def locateTable(){
// creating a variable 'driver' and assigning its value
WebDriver driver = DriverFactory.getWebDriver()
'To locate table'
WebElement Table = driver.findElement(By.xpath("//table[@class='cart']"))
}
This is the test case:
int numcolumns
String columns
WebUI.callTestCase(findTestCase('Smoke Testing/Login'), [:], FailureHandling.STOP_ON_FAILURE)
WebUI.click(findTestObject('Master Object Repository/B2B - My_CES Dropdown/My CES - B2B'))
WebUI.click(findTestObject('Master Object Repository/B2B - My_CES Dropdown/Favorites - B2B'))
// since the table needs to be located first, it should check for its existence
Boolean favtable = CustomKeywords.'com.ces.cesonline.favorites.FavoritesKeywords.locateTable'()
numcolumns = CustomKeywords.'com.ces.cesonline.favorites.FavoritesKeywords.allHeadersFavorites'()
columns = CustomKeywords.'com.ces.cesonline.favorites.FavoritesKeywords.columnNames'()
if (favtable == true){
println ('No. of Columns: ' + numcolumns)
println ('Names of the columns are: ' + columns)
}
else
println('Favorites is empty!')
WebUI.closeBrowser()
When I run it, I get:
no such element: Unable to locate element: {âmethodâ:âxpathâ,âselectorâ:"//table[@class=âcartâ]"}
Thanks
