Neela
Neela

Reputation: 107

Couldn't select the drop down value

I am trying to select the dropdown value . Some times it selects from the drop down. some time i am getting 'Element not visible exception: element not visible'. Its visibility is false when it doesn't choose. So i tried with explicit wait but i am getting time out exception. I have tried using Javascriptexecuotr. Can anyone help me please?

<select class="transport-date-month ddlMonth" 
      data-bind="bookingSelect: travelDate, property: 'month', type: 'date', 
      css: { bindedValue: isBindedFromHoliday() }, 
      event: { change: setArrivalDate() }">
    <option value="-1" selected="selected"></option>
    <option value="Jan">Jan</option>
    <option value="Feb">Feb</option>
    <option value="Mar">Mar</option>
    <option value="Apr">Apr</option>
    <option value="May">May</option>
    <option value="Jun">Jun</option>
    <option value="Jul">Jul</option>
    <option value="Aug">Aug</option>
    <option value="Sep">Sep</option>
    <option value="Oct">Oct</option>
    <option value="Nov">Nov</option>
    <option value="Dec">Dec</option>
</select>

Upvotes: 1

Views: 167

Answers (1)

Eray Balkanli
Eray Balkanli

Reputation: 7960

Real users are simulated via webdriver, so no interaction with invisible or hidden elements is possible. To solve it, add a div, click to div to make the dropdown visible and select an option after. Try something like:

<div class:"myclass">
<select id="selectID" class="transport-date-month ddlMonth"
...
</div>



WebDriverWait wdw= new WebDriverWait(driver, 300);
WebElement we = driver.findElement(By
                .className("myclass"));
we.click();
WebElement selectElement = wdw.until(ExpectedConditions
                  .visibilityOfElementLocated(By.id("selectID")));
Select select = new Select(selectElement);
select.selectByVisibleText("SECURITY");

Upvotes: 1

Related Questions