Java webdriver: element exception not visible

I had the following problem. I have a drop-down menu that is hidden, so when I make a selection 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) 

It is my choice:

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

Is there a walk around him 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 in this case it will not work. Any help would be appreciated.

+6
source share
5 answers

Since WebDriver trying to simulate real users, it cannot interact with invisible / hidden elements. To solve your problem, I think you need to click on the div first to bring it down and select an option from the drop-down list. I would recommend this approach rather than pure Javascript, as it will simulate a real user. Give the next 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 class name triggerDropDown

+7
source
Hey. There can be so many reasons for this. I also came across this problem several times and solved it in different ways.

1- Using WebdriverWait, also known as explicit wait

2 Using unique xpath methods using xpath.

3- Get the size of the item, then click or do any action on the first.

I registered all the solutions here How to solve the item is not visible Exception

+6
source

I absolutely agree with sircapsalot. You must adhere to the business logic of the application and do it as a user. And use this hack only for workarounds.

Answer:

Try this way

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

+1
source

Did not check this, but is the next job doing?

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

0
source

In addition to the reasons and questions raised by earlier answers, I came across another reason worth mentioning. In my case, the JavaScript on the page had to run after clicking the link on the page so that the elements I wanted to get became visible. This is normal as long as your driver has JavaScript enabled. In my case, I worked without JavaScript, so although the link was “clicked” programmatically, the elements did not become visible. I used HtmlUnitDriver with default settings. I ended up switching to ChromeDriver . (You can enable JavaScript on HtmlUnitDriver , but this - for other reasons - was not enough for me in my case.)

0
source

Source: https://habr.com/ru/post/956881/


All Articles