Refactor getting elements by attribute