rubyshadow-domsite-prism

unable to click on checkbox within shadowroot


I am writing a test to go through a test flow of a monetary registration. The registration has Add-ons that appear in different steps that flow. My goal is to be able to select the checkboxes in the add-on shadow root, so I can get to the next step. The elements within the shadow root that I'm trying to focus on seem like they can be targeted, and they are Enumerators, Arrays, and Hashes.

What I need help with is clicking on the checkbox, but the .click method doesn't work for the elements that I'm targeting. I don't return an error for .select, but it doesn't seem to do anything either.

As I step through the code, I think that I am targeting the correct element(s) which is centered around a checkbox. But none of the elements I see seem to be classes that can be "clicked" or interacted with. What I've tried so far:

sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false)).find(css: "label[for='addToCart--false']")

Returns:
#<Enumerator: {"shadow-6066-11e4-a52e-4f735466cecf"=>"416aad9c-c512-496d-93c3-91c17ec6e27d"}:find(css: label[for='addToCart--false'])>
- sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false)).find(id: "addToCart--false")

Returns
#<Enumerator: {"shadow-6066-11e4-a52e-4f735466cecf"=>"416aad9c-c512-496d-93c3-91c17ec6e27d"}:find(id: addToCart--false)>
- sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false))

Returns
{"shadow-6066-11e4-a52e-4f735466cecf"=>"416aad9c-c512-496d-93c3-91c17ec6e27d"}
sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false)).class

Returns
Hash
sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false)).find(id: "addToCart--false").each do |c| puts c, c.class end

Returns
shadow-6066-11e4-a52e-4f735466cecf
416aad9c-c512-496d-93c3-91c17ec6e27d
Array
*** NoMethodError Exception: undefined method `call' for {:id=>"addToCart--false"}:Hash
(byebug) sales_channels_reg.execute_script("return arguments[0].shadowRoot", sales_channels_reg.regsaver_section.regsaver_testtest.find("#sales-channels-element", visible: false)).find(id: "addToCart--false", :visible => false).click
*** NoMethodError Exception: undefined method `click' for #<Enumerator:0x00007fbeb9195558>

nil

Code for what I'm writing

-first file-

describe "Showing 4 max add-ons in reg flow", type: :feature, service: "sales_channels1" do
  context "yadda yadda" do
    subject(:sales_channels_reg) { SalesChannelsRegGenerals.new }
    subject(:se_signup_page) { SELogin.new }
    # subject(:gen_reg) { RegistrationHelper.new }
    let(:form_number) { "848624247" }

    it "in test flow does thing" do
      couple of other steps first
      byebug (where I'm at in the code now)
    end
  end
end

-different file-

require "./spec/page_models/sales_channels_ncsa_section.rb"
require "./spec/page_models/sales_channels_medsaver_section.rb"
require "./spec/page_models/sales_channels_regsaver_section.rb"
require "./spec/page_models/sales_channels_four_addons_section.rb"

class SalesChannelsRegGenerals < SitePrism::Page
  set_url "https://zachpartyka#{SeleniumTest.ngin_site}/register/form/{/form_number}"

  section :regsaver_section, RegSaverSection, "div#siteContainer2"
end

-different file-

class RegSaverSection < SitePrism::Section
  element :regsaver_testtest, "#pageContentContainer"
end

screenshot of html


Solution

  • None of those values should be Enumerators, Hashes, etc (unless site-prism is really screwing with Capybaras returns). I'm guessing the reason is that you're using execute_script when you should be using evaluate_script. execute_script shouldn't be used when you expect a return value, and won't unwrap results into element references, evaluate_script does.

    sales_channels_reg.evaluate_script("arguments[0].shadowRoot", ...)