twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

Using `.option_select` causes test to never finish #69

Closed Nitrodist closed 3 years ago

Nitrodist commented 4 years ago

Hello, I tried invoking .option_select on an <option> node - while it worked, there was a side effect of the chrome window never closing and the test never moving on to the next test despite all of the code in the test being finished.

Removing the call to .option_select fixed the issue, however, I was not able to programmatically select it using the capybara driver. I was able to select my option via bootstrap-select methods (see block below), mostly because my use case is a bootstrap-select enabled select field that maps customer names to their id in the database. I need to make a call to that library anyway, pretty much... however I did in earnest try to use .select_option.

Complicating this matter is that the option was/is invisible due to using bootstrap-select.

This happens if I use headless and if I don't use headless.

My code:

    def self.set_select(page, desired_value, selectpicker_css_selector)
      # <select ... >
      select_element = page.find(selectpicker_css_selector, visible: :all)
      option = select_element.find('option', text: desired_value, visible: :all)

      # If I was able to use this line, I could then use select_element.value() instead of option.value().
      # However, enabling this line below causes the test to never finish.
      # option.select_option 

      sleep 2
      script = "$('#{selectpicker_css_selector}').selectpicker('val', '#{option.value}')"
      page.execute_script(script)
    end
twalpole commented 4 years ago

You shouldn’t be using select_option if the select element is non-visible. Instead you should be interacting directly with the bootstrap-select widgets elements (not via execute_script)

twalpole commented 4 years ago

@Nitrodist This really is more of a Capybara question than an apparition question, but if you provide the HTML the user is actually interacting with I'll try and lead you in the direction you should be using. Likewise if you can provide a simple example where option_select hangs things I will take a look.