Validating Dropdown values of type Input/UL/LI

Need some help in validating dropdown values which are not of type Select/Options.
Dropdown is of Input Type as below.


If i click on each element in dropdown it is of UL/LI Type with different index as below:

Requirement is to validate-Non-Auto Pay is selected and present in the field.

Tried SelectOption by label,value,index and again VerifySelectedOption by label,value,index but it always gives an error as below:

image

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

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!");
}
1 Like