Currently, I am using the JBehave-Web distribution (3.3.4) with Webdriver to conduct testing on an application. I have encountered a peculiar issue:
My challenge lies in interacting with a modalPanel from Richfaces, as it consistently throws an ElementNotVisibleException. To address this, I have resorted to using JavaScript:
Below is the snippet of code from my page object, which extends from org.jbehave.web.selenium.WebDriverPage:
protected void changeModalPanelInputText(String elementId, String textToEnter){
makeNonLazy();
JavascriptExecutor je = (JavascriptExecutor) webDriver();
String script ="document.getElementById('" + elementId + "').value = '" + textToEnter + "';";
je.executeScript(script);
}
What baffles me is that when I run the test normally, nothing happens. However, if I place a breakpoint on the last line (in Eclipse), select the line, and execute it from Eclipse (Ctrl + U), I can observe the changes in the browser.
I have examined the JavascriptExecutor and WebDriver classes to check for any potential buffering mechanisms, but so far, I have come up empty. Any insights?
EDIT Upon experimentation, I have discovered that introducing a 1-second thread sleep allows the code to work. It seems to be some sort of race condition, but the root cause remains elusive...
This is the workaround that somewhat "solves" the issue, although I am not entirely satisfied with it:
protected void changeModalPanelInputText(String elementId, String textToEnter){
String script ="document.getElementById('" + elementId + "').value = '" + textToEnter + "';";
executeJavascript(script);
}
private void executeJavascript(String script){
makeNonLazy();
JavascriptExecutor je = (JavascriptExecutor) webDriver();
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
je.executeScript(script);
}
Attempts to place the wait in different positions have proved futile...