I’m using WebDriver and selenium-firefox-driver version 2.3.1. Now when option.setSelected(); deprecated, one must do option.click(); directly or more exactly :
if (value.equals(option.getAttribute("value"))) {
if(!option.isSelected()) {
option.click();
break;
}
}
The problem is, that I get this exception without reason.
Element is not currently visible and so may not be interacted with
<select id="deadLineDay" name="deadLineDay">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Also, it is definitely not a timing issue… Any idea what the hell is that ? The exception is thrown only sometimes, but as I say, not a timing issue, I’m debugging that
This is the code :
public FillOutForm(WebDriver driver, UploadDocumentPage parent) {
this.driver = driver;
this.parent = parent;
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 3), this);
}
@FindBy(how = How.NAME, using = day)
private WebElement deadLineDay;
@CacheLookup
@FindBy(how = How.NAME, using = hour)
private WebElement deadLineHour;
@CacheLookup
@FindBy(how = How.NAME, using = minute)
private WebElement deadLineMinute;
@CacheLookup
@FindBy(how = How.NAME, using = AmPm)
private WebElement deadLineAmPm;
@CacheLookup
@FindBy(how = How.ID, using = desc)
private WebElement description;
@CacheLookup
@FindBy(how = How.ID, using = comm)
private WebElement comment;
public boolean validationPasses(Map<String, String> map) {
try {
for (String key : map.keySet()) {
WebElement we = (WebElement) this.getClass().getDeclaredField(key).get(this);
setSelectedField(we, map.get(key));
}
} catch (Exception e) {
throw new Error(e.getMessage());
}
valid = elementExists(driver, By.className(validatorError));
return valid;
}
public void setSelectedField(WebElement element, String value) {
List<WebElement> options = element.findElements(By.tagName("option"));
for (WebElement option : options) {
if (value.equals(option.getAttribute("value"))) {
if(!option.isSelected()) {
option.click();
break;
}
}
}
}
Man it might seem hard to believe, but a month ago I often got out of space on disk and suddenly all tests were failing like this. It obviously doesn’t have a reason to fail as far as I can see from the code you pasted…
Also I see you’re using AjaxElementLocatorFactory. Switch to DefaultElementLocatorFactory, it might go away.