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.

2 Answers 2

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;
            }
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome if my answer is satisfy to you please accept my answer so that others can get idea
0

You can make select operations in selenium like that:

//1) 
Select objSelect =new Select(driver.findElement(By.id("search-box")));
objSelect.selectByVisibleText("Automation");

//2) 
Select objSelect = new Select(driver.findElement(By.id("Seacrch-box")));
Select.selectByIndex(4);

//3) 
Select objSelect = new Select(driver.findElement(By.id("Search-box")));
objSelect.selectByValue("Automation Testing");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.