I’ve tried just about every locator, and none of them will detect an element that was appended to the DOM. This is my most recent iteration:
selenium.fireEvent("//button[2]", "click");
waitUntil(new Condition() {
@Override
public boolean evaluate() {
return selenium.isElementPresent("dom=document.getElementsByClassName('dialog-success')[0]");
}
}, (long)60000);
verifyTrue(selenium.isElementPresent("dom=document.getElementsByClassName('dialog-success')[0]"));
The click works, I make an Ajax call, it comes back successfully, and updates the DOM, but the waitUntil method never evaluates to true even though I can see the UI dialog I added.
After trying everything, it was recommended that I use the Selenium IDE plugin for Firefox, which ended up being a life saver. I started recording, and when the UI dialog popped up, I went ahead and closed it. Sure enough, the IDE recorded the click action, but used the index of the DIV in the XPath to locate the element. Knowing then that Selenium would indeed pick up an element dynamically appended with jQuery, I started reviewing my XPath syntax. Unknown to me, jQuery UI (and several other plugins I presume) add additional class names to the UI DOM elements. When I search for an element with a class value string it does not work, however, if you change the XPath to search for class value string using the contains function it will work. Here is what I ended up with: