Check node index atomically to prevent race condition

Fixes Capybara::Webkit::InvalidResponseError when nodes are missing.