Jack
Jack

Reputation: 3

Selenium webdriver not able to select element.Getting "Element is not currently visible and so may not be interacted with" error

I am using selenium webdriver with eclipse,testng & firefox browser I am trying to click a dropdown with id "compName" but I am not able to click it. I have tried all possible scenarios to identify the drodpown but I always get this error "Element is not currently visible and so may not be interacted with" The html code for it is as follows

<div id="login" class="b-container" style="display:block">
<form action="" name="passwordForm" commandname="passwordForm" method="post">
<input id="userVo.email" type="hidden" name="userVo.email">
</form>
<form action="" name="resetForm" commandname="resetForm" method="post"> </form>
<form id="loginForm" class="form-login" onsubmit="return onClickLogin();" name="loginForm" action="" method="post">
<input id="compLocId" type="hidden" name="compLocId" value="1">
<h2 class="form-login-heading">SIGN IN NOW</h2>
<div class="login-wrap">
<div id="invDivMsg" style="color:red;"></div>
<input id="loginId" class="form-control" type="text" placeholder="User ID" name="loginId" disabled="" vk_156ee="subscribed">
<input id="password" class="form-control" type="password" placeholder="Password" name="password" disabled="" vk_156ee="subscribed">
<button id="signIn" class="btn btn-lg btn-info btn-block btn-drop marginLeft23" type="submit" style="width: 80%; display: none;" disabled="">Sign in</button>
<button id="reset" class="btn btn-lg btn-info btn-block btn-drop marginLeft23" onclick="onClickReset()" type="reset" style="width: 80%;">Reset</button>
<div class="select col-md-12">
<select id="compName" onchange="fillLocDrpDown();" name="compName" style="display: block;">
<option value="">Select Company</option>
<option value="5">XYZ ltd</option>
<option value="6">Freight Forwarder Co</option>
<option value="2">CHA</option>
</select>
</div>

Any suggestions are appreciated.

Upvotes: 1

Views: 589

Answers (1)

Guy
Guy

Reputation: 50819

Try to use explicit wait and expected conditions

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("compName")));
element.click();

This will wait up to 10 seconds for the dropdown to be visible.

Upvotes: 1

Related Questions