选择selenium webdriver中的下拉菜单

时间:2015-03-13 09:36:22

标签: selenium selenium-webdriver

我想从下拉列表中选择一个选项。代码如下所示

<select id="hidBrokerId" name="hidBrokerId" style="display: none;">
<option value="" selected="selected">-- Valitse --</option>
<span class="select-sub" style="display: none; left: 0px; top: 50px; width:232px;">
<span data-value="" style="background: none repeat scroll 0% 0% rgb(232, 232, 232);">-- Valitse --</span>
<span data-value="23" style="background: none repeat scroll 0% 0% rgb(255, 255, 255);">Mainos netissä</span> </select>

1 个答案:

答案 0 :(得分:0)

它具有display:none属性,因此您需要操作类导航到该元素并找到它。

WebElement ele = driver.findElement(By.xpath("//select[@id='hidBrokerId' and contains(@style,'display: none')]"));
Actions act = new Actions(driver);
act.moveToElement(ele).click(driver.findElement(By.xpath("//option[contains(text(),'Mainos netissä')]"))).build().perform();

让我知道这是否有效

相关问题