1

Before posting, I researched across stackoverflow to solve this issue but could not find solution as most of them provide solution related to Select class. Some of the links that I did come across and did not solve my issue are below,

  1. How to select a dropdown value in Selenium WebDriver using Java
  2. How to select dropdown value in selenium webdriver using Testng?
  3. How to select dropdown option from span in selenium webdriver
  4. Selenium WebDriver: Handling DropDowns
  5. Select dropdown in selenium webdriver

I have 6 dropdown menus which has same dropdown list and same HTML tags.I am unable to select value from each dropdown menu. One of the dropdown menu looks like below,

1 of 6 dropdown menu

I have HTML with dynamic div ids,

HTML

My xpath to select one of the options is as -> //li[text()='No Problems']. Below method does click on Dropdown menu but fails to click on No Problems. I could not use Select class as DOM does not have select tag.

Below are the 2 different methods that I tried to select dropdown option,

Method to Click on dropdown and select No Problems

Method 2 to select option from dropdown

Please help how to overcome this scenario and select dropdown list option.

GSN
  • 123
  • 2
  • 13

1 Answers1

2
// click on that place holder

     driver.findElement(By.xpath("....')).click();

// then store all results which are inside box by list classes in selenium 

        List <WebElement> lists=driver.findElements(By.xpath("//ul[@role='list box']//li"));
        System.out.println(lists.size());

        for (int i = 0; i < lists.size(); i++) {
            //System.out.println(LIST.get(i).getText());
// checking that text by for loop and pick 
            if (lists.get(i).getText().contains("No Problems")) {
                lists.get(i).click();
                break;
            }
Justin Lambert
  • 940
  • 1
  • 7
  • 13