Why can't Selenium find dynamically added DOM elements?

I added a DOM element (link) with jQuery. I can see an element in Firebug, but for some reason Selenium cannot find it. What's going on here?

Note: AJAX is not involved, so the DOM element is added almost immediately.

== EDIT ==

Here is some code (using jQuery) that adds a link to the end of the document:

$element = $("<a id="foo" href="#"></a>");
$element.appendTo($("body"));

I use Capybara (with Selenium) to find the link and click it like this:

find("#foo").click

I had no problems with Capybara or Selenium until I started adding elements to the DOM using jQuery.

+5
source share
1 answer

Try using waitForElementPresent in the test code.

+6

All Articles