如何单击在单击项目后出现的下拉元素:
<div class="field loan-selection">
<label class="field__body">
<div class="field__label">Nettokreditbetrag
<!-- -->
</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 €</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>
因此,单击元素id="react-select-2663001--value"
下拉菜单出现在此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>
项目aria-activedescendant
会根据列表内的项目数更改值,例如react-select-3--options-2
或末尾为1。
那么会有什么更好的,我可以将以下值更改为20000吗?
<span class="Select-value-label" role="option" aria-selected="true" id="react-select-2663001--value-item">10.000 €</span>
或者我需要单击一些项目,例如:aria-activedescendan="react-select-3--options-2"
答案 0 :(得分:1)
A。所有元素都不必具有id
属性。您可以使用其他属性来使其具有唯一性并找到相同的
现在要解决您的问题:
假设您点击了react-select-2663001--value
,它开始根据您的选择显示一些下拉列表
因此您可以获取以下所有下拉选项
List<WebElement> noOfDropdown = driver.findElement(By.cssSelector("div[aria-activedescendant^='react-select-3--value']"));