我尝试过以下代码:
Select dropdown = new Select(driver.findElement(By.xpath("//a[contains(text(),'--None--')]")));
dropdown.selectByIndex(1);
获得以下错误:
线程中的异常" main" org.openqa.selenium.support.ui.UnexpectedTagNameException:Element 应该是"选择"但是" a"
这是我的完整DOM结构:
<div class="compoundTLRadius compoundTRRadius compoundBorderBottom form-element__row uiMenu" data-aura-rendered-by="2600:0" data-aura-class="uiMenu">
<div id="2574:0" data-aura-rendered-by="2581:0" class="uiPopupTrigger" data-aura-class="uiPopupTrigger" data-interactive-uid="19">
<div data-aura-rendered-by="2583:0"><div data-aura-rendered-by="2576:0">
<a aria-required="false" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Salutation" title="" href="javascript:void(0);" data-aura-rendered-by="2577:0" data-interactive-lib-uid="45">--None--</a>
</div>
</div>
</div>
<div class="select-options popupTargetContainer uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" data-aura-rendered-by="2595:0" data-aura-class="uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" aria-labelledby="2574:0"><div class="select-options" role="menu" data-aura-rendered-by="2589:0"><!--render facet: 2590:0-->
<ul class="scrollable" role="presentation" data-aura-rendered-by="2591:0" data- scoped-scroll="true"><!--render facet: 2592:0--></ul>
</div></div></div>
我想要用于查找下拉图标的代码,然后从中选择第一个值。