在selenium webdriver中选择下拉值时出错

时间:2017-02-23 12:36:06

标签: selenium selenium-webdriver

从下拉列表中,我无法从下拉列表中选择值。

HTML代码:

<select id="ctl00_ContentPlaceHolder1_drp85" class="form-control select2-hidden-accessible" data-varindex="9" onchange="SetVariableValue('9', this, 'DESCENDANT - DROPDOWN')" name="ctl00$ContentPlaceHolder1$drp85" tabindex="-1" aria-hidden="true">
<option value="-1">--Select--</option>
<option value="Please don't hesitate">Please don't hesitate </option>
<option value="Please reach out to us">Please reach out to us</option>
<option value="Remember we are here for you">Remember we are here for you</option>
<option value="If you need help">If you need help</option>
<option value="If you ever need additional help">If you ever need additional help</option>
</select>

Selenium WebDriver代码:

WebElement dropdown = driver.findElement(By.id("ctl00_ContentPlaceHolder1_drp85"));
selectbyindex=new Select(dropdown);
selectbyindex.selectByIndex(1);

将例外情况视为:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated".

任何人都可以帮助我犯错吗?

1 个答案:

答案 0 :(得分:0)

只需等待下拉列表首先显示,然后选择:

new WebDriverWait(driver, TimeSpan.FromSeconds(45)).Until(ExpectedConditions.ElementIsVisible((By.Id("ctl00_ContentPlaceHolder1_drp85"))));