I can’t give you exacting locator pathways without testing more within the actual HTML, but as an example, I might do like below:
import org.openqa.selenium.By as By
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.exception.StepFailedException
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebDriver driver = DriverFactory.getWebDriver()
// get a list of the options
List<WebElement> payments = driver.findElements(By.xpath('//ul[@data-ref="listE1"]/li']))
maxPays = payments.size();
WebUI.comment("Found ${maxPays} items")
// get what I think is "selected"
mySelectedItem = driver.findElement(By.xpath('//input[@data-ref="listE1"]'))
boolean hasFound = false;
// go through the options and see if one of options is my selected one
for (int irow = 0; irow < maxPays; irow++) {
WebUI.comment("We have ${payments.get(irow).getText()}")
if (payments.get(irow).getText() == "Non-Auto Pay") {
WebUI.verifyMatch(payments.get(irow).getText(), mySelectedItem.getAttribute('value'), false)
hasFound = true;
break;
}
}
if (!hasFound) {
throw new StepErrorException("Did not find match!");
}
Edit: I put a failure if we do not find a match within the list. You can probably start without the failure to get the method working. Just comment out those lines.
Edit2: If you haven’t selected the specific text and you need to select the text and then verify you have selected it, then you will need to modify the above slightly:
Maybe like:
import org.openqa.selenium.By as By
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.exception.StepFailedException
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebDriver driver = DriverFactory.getWebDriver()
// get a list of the options
List<WebElement> payments = driver.findElements(By.xpath('//ul[@data-ref="listE1"]/li']))
maxPays = payments.size();
WebUI.comment("Found ${maxPays} items")
// go through the options and see if one of options is my selected one
for (int irow = 0; irow < maxPays; irow++) {
WebUI.comment("We have ${payments.get(irow).getText()}")
if (payments.get(irow).getText() == "Non-Auto Pay") {
payments.get(irow).click();
break;
}
}
// get a list of the options (again)
payments = driver.findElements(By.xpath('//ul[@data-ref="listE1"]/li']))
maxPays = payments.size();
WebUI.comment("Found ${maxPays} items")
// get what I think is "selected"
mySelectedItem = driver.findElement(By.xpath('//input[@data-ref="listE1"]'))
boolean hasFound = false;
// go through the options and see if one of options is my selected one
for (int irow = 0; irow < maxPays; irow++) {
WebUI.comment("We have ${payments.get(irow).getText()}")
if (payments.get(irow).getText() == "Non-Auto Pay") {
WebUI.verifyMatch(payments.get(irow).getText(), mySelectedItem.getAttribute('value'), false)
hasFound = true;
break;
}
}
if (!hasFound) {
throw new StepErrorException("Did not find match!");
}