Scenario: Click a button and a jquery modal dialog appears with input fields and cancel/save buttons. When an input field is empty the save button is disabled and when hovered over, its tooltip displays text.
Testing: Ensuring the tooltip text says what it is supposed to say.
Using: FF v26, ChromeDriver_win32_2.2 and Chrome v31.*, Selenium-java-2.39.0, JQueryUI, and JQuery.tipped.3.2.0.
Problem (both browsers): NoSuchElementException: Unable to locate element:{"method":"id":"selector":"FileNumberRequiredText"}
Javascript:
<script type="text/javascript">
$(document).ready(function() {
$('#new_file_description').prop('maxlength','150');
$("#new_file_number").bind("input keyup paste", toggleSaveButtonEnabled);
function toggleSaveButtonEnabled() {
if ($("#new_file_number").val() == null || $.trim($("#new_file_number").val()) == '') {
var element = Tipped.findElement($("#button-save")[0]);
Tipped.create("#button-save", "<strong id='FileNumberRequiredText'><direct:message key='file.number.required'/></strong>", {
skin: 'custom',
hook: 'rightmiddle'
});
} else {
var element = Tipped.findElement($("#button-save")[0]);
Tipped.remove(element);
}
}
}
</script>
This Test code I have working in a similar case just NOT within the dialog box:
Thread.sleep(5000L);
try {
WebElement webElement = driver.findElement(By.cssSelector("#button-save"));
Actions hover = new Actions(driver);
hover.moveToElement(webElement).build().perform();
WebElement hiddenDiv = driver.findElement(By.id("FileNumberRequiredText"));
String script = "return document.getElementById('FileNumberRequiredText').innerHTML";
String toolTipText = (String) ((JavascriptExecutor) driver).executeScript(script, hiddenDiv);
System.out.println("Tool tip text is: " +toolTipText+"\n");
assertTrue(toolTipText.matches("^[\\s\\S]*File Number is required and cannot be blank\\.[\\s\\S]*$"));
} catch (Error e) {
verificationErrors.append("Text does not match\n"+e.toString());
}
Using FireBug I can see the element is there with its ID.
<div class="t_ContentContainer t_clearfix t_Content_custom">
<strong id="FileNumberRequiredText">File Number is required and cannot be blank.</strong>
</div>
I also have tried pausing after the hover and using a clickAndHold to no avail. Thoughts?
UPDATE: I have since tried the following with no luck:
WebElement hiddenDiv = (new WebDriverWait(driver, 5)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#FileNumberRequiredText")));
AND
WebElement hiddenDiv = (new WebDriverWait(driver, 5)).until(ExpectedConditions.presenceOfElementLocated(By.id("FileNumberRequiredText")));