我正在测试一个web应用程序,其中有v-select vuejs下拉插件为国家字段。如何使用selenium webdriver选择下拉列表中的值。它没有select/div。
下面是从下拉列表中选择国家/地区之前的HTML
<div data-v-ce984332="" id="country-fg" class="mg-t-20">
<p data-v-ce984332="" class="control has-icon has-icon-right">
<div data-v-ce984332="" dir="auto" class="dropdown v-select single searchable" name="country" aria-required="true" aria-invalid="false">
<div class="dropdown-toggle clearfix">
<input type="search" autocomplete="false" placeholder="Country" aria-label="Search for option" class="form-control" style="width: 100%;"> <button type="button" title="Clear selection" class="clear"><span aria-hidden="true">×</span></button> <i role="presentation" class="open-indicator"></i>
<div class="spinner" style="display: none;">Loading...</div>
</div>
<!---->
</div>
<span data-v-ce984332="" class="small tx-warning" style="display: none;"></span></p>
</div>
这是从下拉菜单中选择国家/地区作为美国后的HTML
<div data-v-ce984332="" id="country-fg" class="mg-t-20">
<p data-v-ce984332="" class="control has-icon has-icon-right">
<div data-v-ce984332="" dir="auto" class="dropdown v-select single searchable" name="country" aria-required="true" aria-invalid="true">
<div class="dropdown-toggle clearfix">
<span class="selected-tag">
United States
<!---->
</span>
<input type="search" autocomplete="false" aria-label="Search for option" class="form-control" style="width: auto;"> <button type="button" title="Clear selection" class="clear"><span aria-hidden="true">×</span></button> <i role="presentation" class="open-indicator"></i>
<div class="spinner" style="display: none;">Loading...</div>
</div>
<!---->
</div>
<span data-v-ce984332="" class="small tx-warning" style="display: none;"></span></p>
</div>
发布于 2018-06-08 10:10:12
请指定您正在使用的语言绑定以及到目前为止您尝试过的内容。
Java中的算法:
driver.findElement(By.name("country")).click()
driver.findElement(By.name("country-1")).click()
这些类型的“下拉”字段通常绑定到另一个div
/ element
。
例如,当您点击“dropdown”字段(项目1)时,可能会出现另一个动态div,其中包含某种形式的标签形式的选项。
最常见的例子是<li>, <div>, <span>
。然后,您必须对您想要的选项执行另一个click()
。(第二项)
甚至在某些情况下,下拉div
会包含一个输入标记,您可以对其执行sendKeys()
或setAttribute()
操作,也可以使用javascript直接单击其中一个选项。
建议您提供更多信息,以便我们可以更好地帮助您。
时出现的选项的片段
https://stackoverflow.com/questions/50750279
复制相似问题