vijay vijay - 26 days ago 9
Java Question

how can we select a required value from dropdown which dont have select tag or options tag using selenium?

my html tag is something like this without select tag or options tag.
I want to select required dropdown value using selenium and java.
Can someone help me ?
since i cannot proceed with select, i cannot use it.
Finding it hard to select a value from the dropdown.

<div id="boundlist-1254" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box rp-floating rp-shadow-frame" tabindex="-1" style="right: auto; left: 642px; top: 245px; width: 215px; z-index: 19000; height: 287px;">
<div id="boundlist-1254-listEl" class="x-boundlist-list-ct x-unselectable" role="presentation" style="overflow: auto; height: 287px;">
<ul class="x-list-plain">
<li class="x-boundlist-item" role="option" unselectable="on">*Feb182015</li>
<li class="x-boundlist-item" role="option" unselectable="on">*ShaNili1</li>
<li class="x-boundlist-item" role="option" unselectable="on">1 test supplier</li>
<li class="x-boundlist-item" role="option" unselectable="on">3MTA3</li>
<li class="x-boundlist-item" role="option" unselectable="on">6060 Store Supplier</li>
<li class="x-boundlist-item" role="option" unselectable="on">7885 EL Supplier</li>
<li class="x-boundlist-item" role="option" unselectable="on">A new supplier</li>
<li class="x-boundlist-item" role="option" unselectable="on">A-Mamta-SUp</li>
<li class="x-boundlist-item" role="option" unselectable="on">ANHEUSER BUSCH-STOCKTON</li>
<li class="x-boundlist-item" role="option" unselectable="on">Aarti-MCLANE COMPANY</li>
<li class="x-boundlist-item" role="option" unselectable="on">AutoSupplier12</li>
<li class="x-boundlist-item" role="option" unselectable="on">BAY AREA DISTRIBUTING </li>
<li class="x-boundlist-item" role="option" unselectable="on">BON APPETIT </li>

Answer

I resolved it using the below code Dropdown will be scrolled down element by element until it finds and finally when it finds, it will select it. I have passed xpath as object and value as data:

    JavascriptExecutor jse = (JavascriptExecutor) driver;
    WebElement droplist = driver.findElement(By.xpath(object));
    List<WebElement> droplist_Contents = driver.findElements(By.xpath(object));
    int index = droplist_Contents.size();

    for (int count = 1; count <= index; count++) {

        //elemXPath: combining xpath with index value if the element
        String elemXPath= object+"["+count+"]";
        //content is the run time value of the dropdown value which moves one by one
        String content = driver.findElement(By.xpath(elemXPath)).getText();

        ((JavascriptExecutor) driver).executeScript(
                "arguments[0].scrollIntoView();",
                driver.findElement(By.xpath(elemXPath)));

        if(content.equalsIgnoreCase(data)){
            driver.findElement(By.xpath(elemXPath)).click();
            break;
        }


    }
Comments