elc*_*rua 6 java selenium 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)
Run Code Online (Sandbox Code Playgroud)
这是我的选择:
Select s = new Select(dropDown);
s.selectByVisibleText("CHARGEBACK");
Run Code Online (Sandbox Code Playgroud)
是否有一个漫步来操纵隐藏的元素?我在其中一篇帖子中找到了以下代码:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].scrollIntoView(true);", element);
Run Code Online (Sandbox Code Playgroud)
这是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>
Run Code Online (Sandbox Code Playgroud)
它在这种情况下不起作用.任何帮助,将不胜感激.
由于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");
Run Code Online (Sandbox Code Playgroud)
编辑更新了triggerDropDown的类名
小智 6
嗨这可能有很多原因.我也多次面对这个问题并用不同的方式解决了.
1-使用也称为显式等待的WebdriverWait
2-使用唯一的xpath-使用xpath方式.
3-获取元素的大小,然后单击或在第一个上执行任何操作.
我在这里记录了所有解决方案如何解决元素不可见的异常