<div id="navbarSupportedContent" class="collapse navbar-collapse nav-top-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a id="navbarDropdownMenuLink" class="nav-link dropdown-toggle" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" href="#"> Find a Doctor </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
</li>
<li class="nav-item dropdown">
<a id="navbarDropdownMenuLink" class="nav-link dropdown-toggle" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" href="#"> Online Services </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
</li>
<li class="nav-item dropdown">
<a id="navbarDropdownMenuLink" class="nav-link dropdown-toggle" aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" href="#" rel="nofollow"> About Us </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
</li>
</ul>
<div class="form-inline my-2 my-lg-0 d-none d-sm-block">
</div>
</div>
</nav>
</div>
我想选择包含文字“找医生”的下拉列表。但它显示了多个dropdrown列表,这就是为什么我无法选择一个。
这是我的代码
driver.findElement(By.name(“Find a Doctor”))。click();
我也试过这段代码
driver.findElement(By.xpath( “// DIV [@ ID = 'navbarSupportedContent'] / UL / LI / A”));
答案 0 :(得分:1)
来自文档:
id属性指定HTML元素的唯一ID(值 在HTML文档中必须是唯一的。)
因此,下拉列表具有相同的ID是错误的。