Capybara allows you to filter elements that are focused.
page.find(:fillable_field, focused: true) # Filtering only fillable inputs for performance reasons
page.find(:xpath, '//*', focused: true) # Filter all fields
Legacy approach
In older version, it was possible to use the :focus
pseudo-class. This seems not to work in newer versions anymore.
find(':focus')
Posted by Emanuel to makandra dev (2023-09-07 07:29)