Java webdriver:元素不可见异常

我有以下问题.我有一个隐藏的下拉列表,所以当我进行选择并运行测试时,我得到以下错误
org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated
  (Session info: chrome=30.0.1599.101)

这是我的选择:

Select s = new Select(dropDown);
s.selectByVisibleText("CHARGEBACK");

是否有一个漫步来操纵隐藏的元素?我在其中一篇帖子中找到了以下代码

JavascriptExecutor jse = (JavascriptExecutor) driver;
 jse.executeScript("arguments[0].scrollIntoView(true);",element);

这是HTML代码

<div class="ui-helper-hidden">
<select id="formlevel:levels_input" name="formlevel:levels_input">
<option value="541fac58-5ea8-44ef-9664-e7e48b6c6a3c">Seleccione un Registro</option>
<option value="dafc799c-4d5e-4b02-a882-74cb6ad98902">Security</option>
<option value="e5416086-2036-4cd0-b23e-865747aa3f53">CALL CENTER</option>
<option value="7ea4b4ea-4f06-4d27-9541-1b0cf3f2aa22">CHARGEBACK</option>
<option value="0f915120-7b8f-4a33-b063-5d20a834b655">PREVENÇÃO A FRAUDE</option>
<option value="a8ef13e8-f4a5-43b8-a668-b769f6988565">ANALISE DE CREDITO</option>
<option value="83b65a26-d4cd-43d3-b3fa-2f7894ca454a">SUPORTE A CONTA</option>
<option value="163d0db9-590c-47a7-a271-218b2d27d8d9">REGULARIZAÇÃO FINANCEIRA</option>


在这种情况下不起作用.任何帮助,将不胜感激.

解决方法

由于WebDriver尝试模拟真实用户,因此无法与不可见/隐藏的元素进行交互.为了解决您的问题,我认为您需要首先单击div,这将使下拉显示,并从下拉列表中选择选项.我建议使用这种方法而不是纯Javascript方式,因为它会模拟真实用户.跟着一枪,
webdriverwait wait = new webdriverwait(driver,300);
WebElement triggerDropDown = driver.findElement(By
                .className("ui-helper-hidden"));
triggerDropDown.click();
WebElement selectElement = wait.until(ExpectedConditions
                  .visibilityOfElementLocated(By.id("formlevel:levels_input")));
Select select = new Select(selectElement);
select.selectByVisibleText("Security");

编辑更新了triggerDropDown的类名

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...