Skip to content

Element is not focused with #fill_in? #157

Closed

Description

@YusukeIwaki

Hi, I'm trying several Capybara drivers.
When we evaluate with the following RSpec script (simple GitHub searching), Cuprite doesn't work as expected.

  it 'should search repository' do
    visit '/'

    fill_in('q', with: 'selenium')
    find('a[data-item-type="global_search"]').click

    output = all('.repo-list-item').map do |li|
      li.all('a').first.text
    end
    puts output
    expect(output).to include(match(/selenium/i))
  end
Failures:

  1) github search should search repository
     Failure/Error: find('a[data-item-type="global_search"]').click
     
     Capybara::ElementNotFound:
       Unable to find visible css "a[data-item-type=\"global_search\"]"
     # ./spec/feature/github_search_spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./spec/feature/github_search_spec.rb:8:in `block (2 levels) in <top (required)>'

image

The search button appears only when textbox is focused.
It seems Cuprite inputs 'selenium' text without focusing into the textbox.

We can avoid this issue by explicitly put find("input[name='q']").click before fill_in, however I think it is not so good because some users already have selenium-based specs. It would be useful us to use the existing selenium-based specs also in Cuprite.

Activity

  1. dhnaranjo commented on Nov 16, 2023

    @dhnaranjo

    This issue is still causing trouble.

  2. jdelStrother commented on Dec 16, 2024

    @jdelStrother

    I also ran into this, switching selenium -> cuprite. FWIW, I'm currently using this to work around it:

      Capybara::DSL.prepend(Module.new {
        def fill_in(selector, with:, **opts)
          if page.driver.is_a?(Capybara::Cuprite::Driver)
            find(:fillable_field, selector, **opts).click
          end
          super
        end
      })
  3. seanpdoyle commented on Dec 22, 2025

    @seanpdoyle
    Contributor

    I've opened #305 to attempt to resolve this issue.

  4. route commented on Apr 3, 2026

    @route
    Member

    The UI slightly changed now, I tried to modify the script:

          it 'should search repository' do
            @session.visit '/'
    
            @session.find('//button[@data-target="qbsearch-input.inputButton"]').click
            @session.fill_in('query-builder-test', with: 'selenium')
    
            @session.find(:css, 'span.ActionListItem-description', text: 'Search all of GitHub').click
          end
    

    and it works now, maybe there was something in the markup for prev revision, but now it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions