0
votes

Want to select a value in dropdown textbox , which is the all value , what happens is it produces an error , element was not select but div/span

Tried select dropdown

<div id="ddllocation_chzn" class="chzn-container chzn-container-single" style="width: 398px;"><a href="javascript:void(0)" class="chzn-single" tabindex="-1"><span>ALL 全部</span><div><b></b></div></a>
<div class="chzn-drop" style="left: -9000px; width: 396.008px; top: 24px;">
    <div class="chzn-search">
        <input type="text" autocomplete="off" style="width: 361.016px;">
    </div>
    <ul class="chzn-results">
        <li id="ddllocation_chzn_o_0" class="active-result result-selected" style=""><em>A</em>LL 全部</li>
        <li id="ddllocation_chzn_o_1" class="active-result" style="">Quirino Br<em>a</em>nch Main</li>
        <li id="ddllocation_chzn_o_2" class="active-result" style="">Br<em>a</em>nch 1</li>
        <li id="ddllocation_chzn_o_3" class="active-result" style="">Br<em>a</em>nch 2</li>
        <li id="ddllocation_chzn_o_4" class="active-result" style="">Br<em>a</em>nch 3</li>
        <li id="ddllocation_chzn_o_5" class="active-result" style="">Br<em>a</em>nch 4</li>
    </ul>
</div>

driver.findElement(By.xpath("//span[contains(text(),'Quirino Branch Main')]")).click();
    WebElement location = driver.findElement(By.xpath("//span[contains(text(),'Quirino Branch Main')]"));
    location.click();   

    WebElement Dropdown = driver.findElement(By.xpath("//span[contains(text(),'Quirino Branch Main')]"));
    Select SelectDropdown= new Select(Dropdown);
    SelectDropdown.selectByVisibleText("ALL 全部");

I expect to click the all value

1

1 Answers

0
votes

That drop down is made of ul and li tags so Select class from Selenium will not work. Select class from selenium is meant for select tag in HTML.

Since it is made of ul and li, you have to store elements in a list and try to get web elements and then you can try to click on it.

Steps :

  1. Click on the drop down. You have to write the code for that since no HTML is provided.

  2. Get all drop down elements in a list.

You can try li[id^='ddllocation_chzn'] locator to get all elements in a list like this :

  drop_down = driver.find_elements_by_css_selector('li[id^='ddllocation_chzn']')  
    for drop in drop_down: 
        if drop.text == 'Branch 2':
           drop.click()