When(/^I select an image for the (?:detailed guide|publication)$/) do
  within ".images" do
    attach_file "File", jpg_image
    find(".js-upload-image-input").click # Click event necessary for fieldset cloning.
    fill_in "Alt text", with: "minister of funk", match: :first
  end
end

When(/^I select an image for the (?:detailed guide|publication)$/) do
  within ".images" do
    attach_file "File", jpg_image
    # Click event necessary for fieldset cloning - attaching file doesn't seem
    # to trigger the click event
    page.execute_script("document.querySelector('.js-upload-image-input').dispatchEvent(new CustomEvent('click', { bubbles: true }))")
    fill_in "Alt text", with: "minister of funk", match: :first
  end
end

Fix selenium error for forcing click on input type=file
Fix selenium error for forcing click on input type=file

There is a JS event handler on the input field that needs a click event,
this needs to be done synthetically as chromedriver no longer allows
clicking a file input (oddly).
