Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

element not visible: Element is not currently visible and may not be manipulated - Selenium webdriver

Tags:

selenium

Following is the html

<div id="form1:customertype" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all ui-state-hover" style="width: 165px;">
   <div class="ui-helper-hidden-accessible">
      <select id="form1:customertype_input" name="form1:customertype_input" tabindex="-1">
         <option value="S">Staff</option>
         <option value="C">Customer</option>
         <option value="N">New To Bank</option></select></div>
  <div class="ui-helper-hidden-accessible"><input id="form1:customertype_focus" name="form1:customertype_focus" type="text" readonly="readonly"></div>
  <label id="form1:customertype_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all" style="width: 149px;">Staff</label>
  <div class="ui-selectonemenu-trigger ui-state-default ui-corner-right ui-state-hover"><span class="ui-icon ui-icon-triangle-1-s ui-c"></span></div></div>

The stylesheet of class="ui-helper-hidden-accessible" is

ui-helper-hidden-accessible {
      border: 0;
      clip: rect(0 0 0 0);
      height: 0px;
      margin: -1px;
      overflow: hidden;
      padding: 0;
      position: absolute;
      width: 0px;
   }

Following is my code

    WebElement customerType = driver.findElement(By.id("form1:customertype_input"));
    Select select = new Select(customerType);
    select.selectByVisibleText("New To Bank");

When I try to select "New to Bank" from the dropdown I get exception element not visible: Element is not currently visible and may not be manipulated - Selenium webdriver

I have tried WebDriverWait technique but of no use, any ideas ?

like image 537
Osama Siddiqui Avatar asked Sep 05 '14 06:09

Osama Siddiqui


People also ask

How does selenium handle non visible elements?

Element not visible exception can be resolved by using Explicit wait. Explicit wait in selenium will wait until the element is visible. Once it's visible you can perform the necessary operation. WebDriverWait wait = new WebDriverWait(driver,30); WebElement e = wait.

How can we handle element which is not visible on the screen?

Solution: You need to scroll to element using javascript or Actions class so that element is perfectly visible on screen. By using explicit wait and fluent wait as mentioned above.

Is element visible in selenium?

We can check if an element exists with Selenium webdriver. There are multiple ways to check it. We shall use the explicit wait concept in synchronization to verify the visibility of an element. Let us consider the below webelement and check if it is visible on the page.

When we get element not visible exception?

ElementNotVisibleException occurs when the locators (i.e. id / xpath / css selectors etc) we have provided in the Selenium Program code is trying to find the web element which is in hidden from displaying on the page.


1 Answers

I don't believe the text for that option is actually visible before you attempt to select it. Try selecting by value instead.

WebElement customerType = driver.findElement(By.id("form1:customertype_input"));
Select select = new Select(customerType);
select.selectByValue("N");

You may need to actually click the selector before being able to select an option, though.

WebElement customerType = driver.findElement(By.id("form1:customertype_input"));
new WebDriverWait(driver, 15).until(
            ExpectedConditions.elementToBeClickable(customerType));
customerType.click();

Select select = new Select(customerType);
select.selectByValue("N");
like image 94
Brian Smith Avatar answered Sep 21 '22 09:09

Brian Smith