2017-02-23 87 views
-1

从下拉菜单中,我无法从下拉菜单中选择该值。在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> 

硒的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". 

在哪里可以我会犯错任何人的帮助?

+0

的'期权value'可能不可见。在使用selectByIndex()之前,尝试使用'click()'方法。如果这不起作用,那么在尝试选择选项之前,尝试添加'wait'直到下拉列表实际可见。 – Chaitali

回答

0

只是等待下拉是可见的,然后再选择:除非你点击它

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

支持html下拉菜单 - Select- - <跨度类= “SELECT2-selection__arrow” 角色= “呈现”> <跨度类= “下拉-包装” 咏叹调隐藏=“真“/> –

+0

它不像您所建议的那样工作。 –

+0

我认为你使用了错误的定位器。尝试使用Xpath ID contains- // * [contains(@ id,'ctl00_ContentPlaceHolder1_drp85')] –

相关问题