如何在Selenium中选择带有Span标签的下拉元素

时间:2019-01-02 12:19:21

标签: html selenium

我正在尝试从Selenium中带有Span标签的Dropdown中选择一个选项。下面是我的硒代码

new Select (driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single"))).selectByVisibleText("Prison");

遇到错误'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "span"'

下拉菜单的HTML代码如下;

HTML code

请寻求任何帮助。

1 个答案:

答案 0 :(得分:0)

您不能在选择课程中使用。尝试 Select sel = new Select(driver.findelement(By.id('P37_ACCOMMODATION_STATUS'))); sel.SelectByVisibleText('Prision');