How to handle WebElement Dropdown whose tag starts with <Span>?

  • Script is selecting country element then entering Text in Search field as "India" which shows 2 values in search result . I am unable to select displayed field value ?

    Test Case Ⓜ 1. Navigate to Country ( Please select ) 2. Search box is displayed - Example Sendkeys "India" 3. List of Countries displayed

    HTML Code for Country Element ( Please select )

    enter image description here

    HTML Code for Search text box in dropdown enter image description here

    //Dropdown & Search by Text India

        System.out.println("You are able to click on Dropdown");
        driver.findElement(By.xpath("//*[@id=\"oj-listbox-drop\"]/div/div/input")).sendKeys("United States");

  • I have also got a autocomplete text box options, so for that i have just created the method which used to control it, may this help you please modify it with your use:-

    public static void selectAutoSearchText(By selectBoxElement,By textBoxElement, By dropdownElement, String textValue, String matchingValue, WebDriver driver, WebDriverWait wait) throws InterruptedException
            try {
                WebElement searchBox= wait.until(ExpectedConditions.visibilityOfElementLocated(textBoxElement));
                WebElement waitElement= wait.until(ExpectedConditions.visibilityOfElementLocated(dropdownElement));
                List<WebElement> dropdownList= waitElement.findElements(By.tagName("tr"));
                for(WebElement listElement :dropdownList)
            } catch (Exception e) {
                // TODO Auto-generated catch block

    I have used both Explicit Wait and Thread.sleep just because by drop down options value loaded after some time, so in some cases it failed to select options so i used the thread.sleep to reduce it.

    In this you just need to pass the Xpath of these values and text which you will enter and matching value is for select that country name on which you want click for select that option.

    I have used tag name


    you can change it according to your options tag because it can be Button or Span tag also.

Suggested Topics