【问题标题】:Selecting drop down in selenium webdriver在 selenium webdriver 中选择下拉菜单
【发布时间】:2024-04-18 10:05:02
【问题描述】:

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

<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>

【问题讨论】:

  • 我想选择 Mainos netissä 选项
  • 更新答案请检查

标签: selenium selenium-webdriver


【解决方案1】:

它具有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();

让我知道这是否有效

【讨论】:

  • 您能否正确发布您的html?我看到它有style='display-none
  • 您好,运行脚本时出错,因为“必须为移动操作提供位置。”
猜你喜欢
相关资源
最近更新 更多
热门标签