6

I'm having the following problem. I have a dropdown that is hidden so when I make the Select and run the test i get the following error:

 org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated
  (Session info: chrome=30.0.1599.101)

This is my select:

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

Is there a walk around it to manipulate hidden elements?. I found the following code in one of the posts:

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

This is the html code:

 <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>

And it doesn't work in this case. Any help would be appreciated.

5
  • 5
    Why don't you make a valid test case that makes it visible, e.g. click this, then change the dropdown when the element is visible It's bad test logic to manipulate hidden elements as users will not do this. Commented Oct 28, 2013 at 14:33
  • 1
    Also, if the element is supposed to be visible, and its throwing this error, then I would check your selector. You may be selecting the wrong element. Commented Oct 28, 2013 at 14:40
  • The selector is fine because i can find the element but I can't select the option. P.S added the html code. Commented Oct 28, 2013 at 14:51
  • @user2752065 did you try my answer? Commented Oct 31, 2013 at 13:58
  • @sircapsalot actually, users will do this. jquery-ui uses hidden elements all the time. It seems difficult to test this. I don't want to use the visible jquery-ui element, because the graphic department may change that tomorrow. The underlying element holding the value is the most stable way to test. Commented Sep 27, 2018 at 17:22

5 Answers 5

7

Since WebDriver tries to simulate real users, it cannot interact with elements which are invisible/hidden. To solve your issue, I think you would need to click on div first which will make the drop down visible and select option from the dropdown. I would recommend such an approach as opposed to pure Javascript way since it would simulate a real user. Give following a shot,

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");

Edit updated the class name of triggerDropDown

Sign up to request clarification or add additional context in comments.

1 Comment

I agree with this answer. You wouldn't need to use a FluentWait (ignoring exceptions) on this type of interaction (because the div click has a immediate expected result) and so the WebDriverWait is perfect in this context.
6

Hi There can be so many reason for this. I also faced this issue number of times and solved using different ways.

1- Using WebdriverWait that is also know as explicit wait

2- Using unique xpath- using xpath ways.

3- Get the size of element then click or perform any action on first one.

I documented all solution here How to Solve Element not visible Exception

Comments

1

I absolutely agree to sircapsalot. You should hold application business logic and "do like an user". And use this hack for workarounds only.

Answer:

Try this way

document.getElementById('formLevel:levels_input').options[3].selected = "true"

Comments

0

Haven't tested this, but does the following work?

s.selectByValue("7ea4b4ea-4f06-4d27-9541-1b0cf3f2aa22");

Comments

0

In addition to the reasons and issues raised by the earlier answers, I encountered another cause worth mentioning. In my case, a JavaScript on the page had to run after clicking a link on the page in order for the elements that I wanted to access to become visible. That's ok as long as your driver has JavaScript enabled. In my case, I was running without JavaScript, so even though the link was "clicked" programmatically, the elements were not becoming visible. I was using HtmlUnitDriver with the default settings. Ultimately I switched to ChromeDriver. (You can enable JavaScript on HtmlUnitDriver, but that - for other reasons - was not enough for me in my case.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.