Hi All,
This could be quite a complicated query for a first post, I have been working with the Scripting section of Katalon for a week or two now and finding it very useful. However I am currently attempting to find out if a Checkbox is enabled or disabled through using WebElement.
Background of the script:
The script dynamically goes through all Objects within the Object Repository and each item listed is looped through, therefore making it much easier for me to add multiple webpages going forward. The script then scrapes mostly just the text from each page and imports this into an excel spreadsheet, each webpage is given its own sheet so that it can be analysed easier going forward.
I am currently finding the tables on the web pages using xpath:
String rowSeparator = 'tr'
String columnSeparator = 'td'
String varxpath = findTestObject(obj).findXpathValue('xpath:idRelative')
WebDriver driver = DriverFactory.getWebDriver()
WebElement Table = driver.findElement(By.xpath(varxpath))
List<WebElement> rows_table = Table.findElements(By.tagName(rowSeparator))
I then loop through all the elements in the table:
int rows_count = rows_table.size()
for (int rownum = 0; rownum < rows_count; rownum++) {
String ro = rows_count
log.logInfo(ro)
log.logInfo('New Row')
List<WebElement> Columns_row = rows_table.get(rownum).findElements(By.tagName(columnSeparator))
Then do the same for the columns within the rows and get the text:
int columns_count = Columns_row.size()
for (int columnnum = 0; columnnum < columns_count; columnnum++) {
String celltext = Columns_row.get(columnnum).getText()
If the text isnt blank then it will add it to the cell or if it is blank I am trying to check if its a check box and then output the value. However I cannot seem to get any indicator to prove if the item within the column is a checkbox or not(as you can see I have tried many different attribute variants to see what could work):
if (celltext != ‘’) {
sheet.getRow(RowCount).createCell(4 + columnnum).setCellValue(celltext)
}
else {
if (columnnum == 0){
log.logInfo(‘First Cell Is Blank’)
String AttributeTest = Columns_row.get(columnnum).getAttribute(“class”)
log.logInfo(AttributeTest)
AttributeTest = Columns_row.get(columnnum).getAttribute(“type”)
log.logInfo(AttributeTest)
AttributeTest = Columns_row.get(columnnum).getAttribute(“input”)
log.logInfo(AttributeTest)
AttributeTest = Columns_row.get(columnnum).getAttribute(“div”)
log.logInfo(AttributeTest)
AttributeTest = Columns_row.get(columnnum).getAttribute(“checked”)
log.logInfo(AttributeTest)
List AttributeElements = Columns_row.get(columnnum).findElements(By.tagName(“input”))
log.logInfo(AttributeElements)
AttributeTest = AttributeElements.getAttribute(“checked”)
log.logInfo(AttributeTest)
if (Columns_row.get(columnnum).getAttribute("type") == 'checkbox')
{
log.logInfo('Attribute is a checkbox')
if (Columns_row.get(columnnum).getAttribute("checked") == 'checked') {
sheet.getRow(RowCount).createCell(4 + columnnum).setCellValue('Allowed')
}
else
{
sheet.getRow(RowCount).createCell(4 + columnnum).setCellValue('Blocked')
}
}
else {
log.logInfo('Attribute is not a checkbox')
//Uncomment once completed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//columnnum = columns_count
}
WebUI.delay(10, FailureHandling.STOP_ON_FAILURE)
}
}
The only Attribute that comes back with any data is “class” and this comes back as blank, all others show as null. Also currently “List AttributeElements = Columns_row.get(columnnum).findElements(By.tagName(“input”))” errors out, that was my most recent attempt at resolving my issue.
The HTML I am analysing is, in bold is what I am trying to identify:
Unknown URLs
Unknown | Override | File Extension | |||
---|---|---|---|---|---|
Unknown
Unknown URLs, Domains and IP Addresses
|
None SelectedAudio FilesCompressed FilesExecutable FilesVideo Files | ||||
Unknown YouTube
(Smart Play must be enabled in General > Video Filtering.)
|
Any help would be greatly appreciated, I am going to continue working on this and will update if I find a resolution to my issue. Let me know if anymore information is required or I am going down the wrong rabbit hole