It turns out that other engines also prefer <h1 id=x> over <a name=x>. So we can just use get_element_by_id() directly without worrying about the type of element we find.