Lahiru Madhawa
Lahiru Madhawa

Reputation: 13

click on button which have values from array or list

I have a list of dropdown predefine values from the web site as below

"KSA", "UAE", "Bahrain", "Oman", "Qatar", "Kuwait","Egypt","Jordan", "Tunisia" , "Morocco", "Palestine","Iraq"

need a helping selenium/ katalon code for click on those values

Upvotes: 1

Views: 179

Answers (2)

Mate Mrše
Mate Mrše

Reputation: 8394

Put the countries in a list and if the dropdown is a select element, you can use the following code to select, for example "KSA":

def countries = ["KSA", "UAE", "Bahrain", "Oman", "Qatar", "Kuwait","Egypt","Jordan", "Tunisia" , "Morocco", "Palestine","Iraq"]
WebUI.click(findTestObject('dropdown-element'))
WebUI.selectOptionByValue(findTestObject('dropdown-element'), countries[0], false)

Upvotes: 1

Deepak
Deepak

Reputation: 13

if you are using c#, then try this

        IWebDriver driver = new ChromeDriver();

        IList<IWebElement> dropdownLists = driver.FindElements(By.Id("yourdropdown"));
        foreach (IWebElement item in dropdownLists)
        {
            if (item.Text.Equals("KSA"))
            {
                item.Click();
            }

            //if(item.Text.Equals("UAE")) ..... etc
        }

you can also use a switch condition to select your place within the foreach statement

Upvotes: 0

Related Questions