Some help with Select Option

This may help some people with selecting options from a drop down

package com.generaluse

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows

import groovy.inspect.swingui.BytecodeCollector

import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.util.KeywordUtil

import internal.GlobalVariable

public class SelectOption {
	@Keyword
	def Option (def choice) {
		WebDriver driver = DriverFactory.getWebDriver();
		WebElement myTable = driver.findElement(By.xpath('//div[@role="listbox"]'))

		List<WebElement> cells_in_table = myTable.findElements(By.xpath('//mat-option[@role="option"]'))
		'To calculate no of rows In table'
		int cell_count = cells_in_table.size()
		boolean found = false

		Loop:
		for (int cell = 0; cell < cell_count; cell++) {

			String celltext = cells_in_table.get(cell).getText().trim();

			if (celltext == choice) {
				cells_in_table.get(cell).click();
				found = true
				break Loop;
			}
		}
		if (found == false) {
			KeywordUtil.markFailedAndStop("Dropdown option not found!")
		}
	}
}

public class CountRows {
	@Keyword
	def Table (def table) {
		WebDriver driver = DriverFactory.getWebDriver ()
		WebElement Table = driver.findElement(By.xpath(table))
		List<WebElement> table_row = Table.findElements(By.tagName('tr'))
		int rowCount = table_row {
			return (table_row)
		} {
		}
	}
}
1 Like