简体   繁体   中英

How to click on drop-down list which doesn't have id

How to click on drop-down element which appears after clicking on item:

<div class="field loan-selection">
    <label class="field__body">
        <div class="field__label">Nettokreditbetrag
            <!-- -->&nbsp;
        </div>
        <div class="field__control">
            <div class="Select customSelect has-value Select--single">
                <div class="Select-control">
                    <span class="Select-multi-value-wrapper" id="react-select-2663001--value">
                        <div class="Select-value">
                            <span class="Select-value-label" role="option" aria-selected="true" id="react-select-2663001--value-item">10.000&nbsp;€</span>
                        </div>
                        <div aria-expanded="false" aria-owns="" aria-activedescendant="react-select-3--value" aria-disabled="false" class="Select-input" role="combobox" style="border:0;width:1px;display:inline-block" tabindex="0"></div>
                    </span>
                    <span class="Select-arrow-zone">
                        <span class="Select-arrow"></span>
                    </span>
                </div>
            </div>
        </div>
    </label>
</div>

So, after clicking on element: id="react-select-2663001--value"

Drop down menu appears inside this div:

<div aria-expanded="false" aria-owns="" aria-activedescendant="react-select-3--value" aria-disabled="false" class="Select-input" role="combobox" style="border:0;width:1px;display:inline-block" tabindex="0"></div> 

And item aria-activedescendant change value according number of item inside the list, for example react-select-3--options-2 or 1 in the end.

So what will be better, can i just change the value for 20 000 for:

<span class="Select-value-label" role="option" aria-selected="true" id="react-select-2663001--value-item">10.000&nbsp;€</span>

or i need to click in some item like: aria-activedescendan="react-select-3--options-2"

Q. How to click on drop-down list which doesn't have id

A. Its not necessary that all element should have id attribute. You can use other attributes to make that unique and locate the same

Now about your problem :

Suppose you clicked on react-select-2663001--value and it started showing some dropdown based on your selection

So either you can get all the dropdown option as below

List<WebElement> noOfDropdown = driver.findElement(By.cssSelector("div[aria-activedescendant^='react-select-3--value']"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM